Skip to content

Commit

Permalink
More paranoia
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed May 18, 2017
1 parent df6ce90 commit 049d06c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions UI/TextureUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
10 changes: 9 additions & 1 deletion ext/native/gfx/gl_lost_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <vector>
#include <mutex>

#include "base/basictypes.h"
#include "base/logging.h"
Expand All @@ -10,13 +11,15 @@ struct Holder {
int priority;
};

static std::mutex mutex;
std::vector<Holder> *holders;

static bool inLost;
static bool inRestore;
static int g_max_priority = 0;

void register_gl_resource_holder(GfxResourceHolder *holder, const char *desc, int priority) {
std::lock_guard<std::mutex> lock(mutex);
if (inLost || inRestore) {
FLOG("BAD: Should not call register_gl_resource_holder from lost/restore path");
return;
Expand All @@ -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<std::mutex> lock(mutex);
if (inLost || inRestore) {
FLOG("BAD: Should not call unregister_gl_resource_holder from lost/restore path");
return;
Expand All @@ -53,6 +57,7 @@ void unregister_gl_resource_holder(GfxResourceHolder *holder) {
}

void gl_restore() {
std::lock_guard<std::mutex> lock(mutex);
inRestore = true;
if (!holders) {
WLOG("GL resource holder not initialized, cannot process restore request");
Expand All @@ -75,6 +80,7 @@ void gl_restore() {
}

void gl_lost() {
std::lock_guard<std::mutex> lock(mutex);
inLost = true;
if (!holders) {
WLOG("GL resource holder not initialized, cannot process restore request");
Expand All @@ -97,6 +103,7 @@ void gl_lost() {
}

void gl_lost_manager_init() {
std::lock_guard<std::mutex> lock(mutex);
if (holders) {
FLOG("Double GL lost manager init");
// Dead here (FLOG), no need to delete holders
Expand All @@ -106,6 +113,7 @@ void gl_lost_manager_init() {
}

void gl_lost_manager_shutdown() {
std::lock_guard<std::mutex> lock(mutex);
if (!holders) {
FLOG("Lost manager already shutdown");
} else if (holders->size() > 0) {
Expand All @@ -114,4 +122,4 @@ void gl_lost_manager_shutdown() {

delete holders;
holders = 0;
}
}

0 comments on commit 049d06c

Please sign in to comment.