Qt: Fix gl-gs-frame error in debug builds

This commit is contained in:
Megamouse 2025-01-24 19:55:38 +01:00
parent f1f85335a7
commit 3c53c52279

View file

@ -35,20 +35,20 @@ void gl_gs_frame::reset()
draw_context_t gl_gs_frame::make_context() draw_context_t gl_gs_frame::make_context()
{ {
auto context = new GLContext(); GLContext* context = nullptr;
// Workaround for the Qt warning: "Attempting to create QWindow-based QOffscreenSurface outside the gui thread. Expect failures."
// This is also necessery in debug builds.
Emu.BlockingCallFromMainThread([&]()
{
context = new GLContext();
context->handle = new QOpenGLContext(); context->handle = new QOpenGLContext();
if (m_primary_context) if (m_primary_context)
{ {
QOffscreenSurface* surface = nullptr; QOffscreenSurface* surface = new QOffscreenSurface();
// Workaround for the Qt warning: "Attempting to create QWindow-based QOffscreenSurface outside the gui thread. Expect failures."
Emu.BlockingCallFromMainThread([&]()
{
surface = new QOffscreenSurface();
surface->setFormat(m_format); surface->setFormat(m_format);
surface->create(); surface->create();
});
// Share resources with the first created context // Share resources with the first created context
context->handle->setShareContext(m_primary_context->handle); context->handle->setShareContext(m_primary_context->handle);
@ -69,6 +69,7 @@ draw_context_t gl_gs_frame::make_context()
{ {
fmt::throw_exception("Failed to create OpenGL context"); fmt::throw_exception("Failed to create OpenGL context");
} }
});
return context; return context;
} }
@ -80,10 +81,16 @@ void gl_gs_frame::set_current(draw_context_t ctx)
fmt::throw_exception("Null context handle passed to set_current"); fmt::throw_exception("Null context handle passed to set_current");
} }
// Calling this on the main thread is necessery in debug builds.
Emu.BlockingCallFromMainThread([&]()
{
const auto context = static_cast<GLContext*>(ctx); const auto context = static_cast<GLContext*>(ctx);
if (!context->handle->makeCurrent(context->surface)) if (context->handle->makeCurrent(context->surface))
{ {
return;
}
if (!context->owner) if (!context->owner)
{ {
create(); create();
@ -100,14 +107,18 @@ void gl_gs_frame::set_current(draw_context_t ctx)
{ {
fmt::throw_exception("Could not bind OpenGL context"); fmt::throw_exception("Could not bind OpenGL context");
} }
} });
} }
void gl_gs_frame::delete_context(draw_context_t ctx) void gl_gs_frame::delete_context(draw_context_t ctx)
{ {
const auto gl_ctx = static_cast<GLContext*>(ctx); const auto gl_ctx = static_cast<GLContext*>(ctx);
// Calling this on the main thread is necessery in debug builds.
Emu.BlockingCallFromMainThread([&]()
{
gl_ctx->handle->doneCurrent(); gl_ctx->handle->doneCurrent();
});
#ifdef _MSC_VER #ifdef _MSC_VER
//AMD driver crashes when executing wglDeleteContext //AMD driver crashes when executing wglDeleteContext