diff --git a/SDL/SDLGLGraphicsContext.cpp b/SDL/SDLGLGraphicsContext.cpp index 51cbde1470..f8f69fd02c 100644 --- a/SDL/SDLGLGraphicsContext.cpp +++ b/SDL/SDLGLGraphicsContext.cpp @@ -126,3 +126,17 @@ int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std: window_ = window; return 0; } + +void SDLGLGraphicsContext::Shutdown() { +} + +void SDLGLGraphicsContext::ShutdownFromRenderThread() { + delete draw_; + draw_ = nullptr; + +#ifdef USING_EGL + EGL_Close(); +#else + SDL_GL_DeleteContext(glContext); +#endif +} diff --git a/SDLGLGraphicsContext.h b/SDLGLGraphicsContext.h index 30518585e1..71f130a4f7 100644 --- a/SDLGLGraphicsContext.h +++ b/SDLGLGraphicsContext.h @@ -11,20 +11,12 @@ class SDLGLGraphicsContext : public DummyGraphicsContext { public: SDLGLGraphicsContext() { } - ~SDLGLGraphicsContext() { - delete draw_; - } // Returns 0 on success. int Init(SDL_Window *&window, int x, int y, int mode, std::string *error_message); - void Shutdown() override { -#ifdef USING_EGL - EGL_Close(); -#else - SDL_GL_DeleteContext(glContext); -#endif - } + void Shutdown() override; + void ShutdownFromRenderThread() override; void SwapBuffers() override { renderManager_->Swap(); diff --git a/ext/native/thin3d/GLRenderManager.cpp b/ext/native/thin3d/GLRenderManager.cpp index 67da177dba..ef802f4729 100644 --- a/ext/native/thin3d/GLRenderManager.cpp +++ b/ext/native/thin3d/GLRenderManager.cpp @@ -54,7 +54,7 @@ GLRenderManager::GLRenderManager() { GLRenderManager::~GLRenderManager() { for (int i = 0; i < MAX_INFLIGHT_FRAMES; i++) { - + // _assert_(frameData_[i].deleter.IsEmpty()); } if (!useThread_) { diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index fe16fa9687..87b4b0bb8c 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -194,6 +194,9 @@ public: int semanticsMask_ = 0; }; +// Note: The GLRenderManager is created and destroyed on the render thread, and the latter +// happens after the emu thread has been destroyed. Therefore, it's safe to run wild deleting stuff +// directly in the destructor. class GLRenderManager { public: GLRenderManager(); diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 91868b4095..9799d8de4a 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -477,7 +477,7 @@ private: OpenGLTexture *boundTextures_[8]{}; int maxTextures_ = 0; DeviceCaps caps_{}; - + // Bound state OpenGLPipeline *curPipeline_ = nullptr; OpenGLBuffer *curVBuffers_[4]{}; @@ -519,7 +519,7 @@ OpenGLContext::OpenGLContext() { default: caps_.vendor = GPUVendor::VENDOR_UNKNOWN; break; - } + } for (int i = 0; i < GLRenderManager::MAX_INFLIGHT_FRAMES; i++) { frameData_[i].push = new GLPushBuffer(&renderManager_, GL_ARRAY_BUFFER, 64 * 1024); renderManager_.RegisterPushBuffer(i, frameData_[i].push);