diff --git a/UI/TextureUtil.h b/UI/TextureUtil.h index ce512d76abe8..180d764727b0 100644 --- a/UI/TextureUtil.h +++ b/UI/TextureUtil.h @@ -21,10 +21,10 @@ class ManagedTexture : public GfxResourceHolder { register_gl_resource_holder(this, "managed_texture", 0); } ~ManagedTexture() { - if (texture_) - texture_->Release(); if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) unregister_gl_resource_holder(this); + if (texture_) + texture_->Release(); } void GLLost() override { if (texture_) diff --git a/ext/native/gfx/gl_lost_manager.cpp b/ext/native/gfx/gl_lost_manager.cpp index 915842e64546..fe95306f66bd 100644 --- a/ext/native/gfx/gl_lost_manager.cpp +++ b/ext/native/gfx/gl_lost_manager.cpp @@ -1,4 +1,5 @@ #include +#include #include "base/basictypes.h" #include "base/logging.h" @@ -10,6 +11,7 @@ struct Holder { int priority; }; +static std::mutex mutex; std::vector *holders; static bool inLost; @@ -17,6 +19,7 @@ static bool inRestore; static int g_max_priority = 0; void register_gl_resource_holder(GfxResourceHolder *holder, const char *desc, int priority) { + std::lock_guard lock(mutex); if (inLost || inRestore) { FLOG("BAD: Should not call register_gl_resource_holder from lost/restore path"); return; @@ -31,6 +34,7 @@ void register_gl_resource_holder(GfxResourceHolder *holder, const char *desc, in } void unregister_gl_resource_holder(GfxResourceHolder *holder) { + std::lock_guard lock(mutex); if (inLost || inRestore) { FLOG("BAD: Should not call unregister_gl_resource_holder from lost/restore path"); return; @@ -53,6 +57,7 @@ void unregister_gl_resource_holder(GfxResourceHolder *holder) { } void gl_restore() { + std::lock_guard lock(mutex); inRestore = true; if (!holders) { WLOG("GL resource holder not initialized, cannot process restore request"); @@ -75,6 +80,7 @@ void gl_restore() { } void gl_lost() { + std::lock_guard lock(mutex); inLost = true; if (!holders) { WLOG("GL resource holder not initialized, cannot process restore request"); @@ -97,6 +103,7 @@ void gl_lost() { } void gl_lost_manager_init() { + std::lock_guard lock(mutex); if (holders) { FLOG("Double GL lost manager init"); // Dead here (FLOG), no need to delete holders @@ -106,6 +113,7 @@ void gl_lost_manager_init() { } void gl_lost_manager_shutdown() { + std::lock_guard lock(mutex); if (!holders) { FLOG("Lost manager already shutdown"); } else if (holders->size() > 0) { @@ -114,4 +122,4 @@ void gl_lost_manager_shutdown() { delete holders; holders = 0; -} +} \ No newline at end of file