mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-12-06 07:12:28 +01:00
gl: Fix crashes when creating new context
This commit is contained in:
parent
cffc13696d
commit
3c3197d72d
|
|
@ -35,37 +35,43 @@ void gl_gs_frame::reset()
|
||||||
|
|
||||||
draw_context_t gl_gs_frame::make_context()
|
draw_context_t gl_gs_frame::make_context()
|
||||||
{
|
{
|
||||||
|
// This whole function should run in the main GUI thread.
|
||||||
|
// This really matters on Windows where a lot of wgl internals are stashed in the TEB.
|
||||||
|
|
||||||
auto context = new GLContext();
|
auto context = new GLContext();
|
||||||
context->handle = new QOpenGLContext();
|
context->handle = new QOpenGLContext();
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
if (m_primary_context)
|
Emu.BlockingCallFromMainThread([&]()
|
||||||
{
|
{
|
||||||
QOffscreenSurface* surface = nullptr;
|
if (m_primary_context)
|
||||||
|
|
||||||
// Workaround for the Qt warning: "Attempting to create QWindow-based QOffscreenSurface outside the gui thread. Expect failures."
|
|
||||||
Emu.BlockingCallFromMainThread([&]()
|
|
||||||
{
|
{
|
||||||
surface = new QOffscreenSurface();
|
QOffscreenSurface* 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);
|
||||||
context->surface = surface;
|
context->surface = surface;
|
||||||
context->owner = true;
|
context->owner = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This is the first created context, all others will share resources with this one
|
// This is the first created context, all others will share resources with this one
|
||||||
m_primary_context = context;
|
m_primary_context = context;
|
||||||
context->surface = this;
|
context->surface = this;
|
||||||
context->owner = false;
|
context->owner = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->handle->setFormat(m_format);
|
context->handle->setFormat(m_format);
|
||||||
|
|
||||||
if (!context->handle->create())
|
if (!context->handle->create())
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!success)
|
||||||
{
|
{
|
||||||
fmt::throw_exception("Failed to create OpenGL context");
|
fmt::throw_exception("Failed to create OpenGL context");
|
||||||
}
|
}
|
||||||
|
|
@ -110,8 +116,8 @@ void gl_gs_frame::delete_context(draw_context_t ctx)
|
||||||
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, probably because the current thread does not own the context.
|
||||||
//Catch with SEH
|
// Catch with SEH
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
delete gl_ctx->handle;
|
delete gl_ctx->handle;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue