SDL: Fix crashing on GB game exit

This commit is contained in:
Jeffrey Pfau 2016-01-22 20:25:13 -08:00
parent eb19998e14
commit 77886d4cf4
1 changed files with 17 additions and 6 deletions

View File

@ -23,17 +23,18 @@ static void _doViewport(int w, int h, struct VideoBackend* v) {
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
static bool mSDLGLInitGBA(struct mSDLRenderer* renderer); static bool mSDLGLInitGBA(struct mSDLRenderer* renderer);
static void mSDLGLRunloopGBA(struct mSDLRenderer* renderer, void* user); static void mSDLGLRunloopGBA(struct mSDLRenderer* renderer, void* user);
static void mSDLGLDeinitGBA(struct mSDLRenderer* renderer);
#endif #endif
#ifdef M_CORE_GB #ifdef M_CORE_GB
static bool mSDLGLInitGB(struct mSDLRenderer* renderer); static bool mSDLGLInitGB(struct mSDLRenderer* renderer);
static void mSDLGLRunloopGB(struct mSDLRenderer* renderer, void* user); static void mSDLGLRunloopGB(struct mSDLRenderer* renderer, void* user);
static void mSDLGLDeinitGB(struct mSDLRenderer* renderer);
#endif #endif
static void mSDLGLDeinit(struct mSDLRenderer* renderer);
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
void mSDLGLCreate(struct mSDLRenderer* renderer) { void mSDLGLCreate(struct mSDLRenderer* renderer) {
renderer->init = mSDLGLInitGBA; renderer->init = mSDLGLInitGBA;
renderer->deinit = mSDLGLDeinit; renderer->deinit = mSDLGLDeinitGBA;
renderer->runloop = mSDLGLRunloopGBA; renderer->runloop = mSDLGLRunloopGBA;
} }
@ -80,12 +81,22 @@ void mSDLGLRunloopGBA(struct mSDLRenderer* renderer, void* user) {
v->swap(v); v->swap(v);
} }
} }
void mSDLGLDeinitGBA(struct mSDLRenderer* renderer) {
if (renderer->gl.d.deinit) {
renderer->gl.d.deinit(&renderer->gl.d);
}
free(renderer->d.outputBuffer);
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_GL_DeleteContext(renderer->glCtx);
#endif
}
#endif #endif
#ifdef M_CORE_GB #ifdef M_CORE_GB
void mSDLGLCreateGB(struct mSDLRenderer* renderer) { void mSDLGLCreateGB(struct mSDLRenderer* renderer) {
renderer->init = mSDLGLInitGB; renderer->init = mSDLGLInitGB;
renderer->deinit = mSDLGLDeinit; renderer->deinit = mSDLGLDeinitGB;
renderer->runloop = mSDLGLRunloopGB; renderer->runloop = mSDLGLRunloopGB;
} }
@ -155,14 +166,14 @@ void mSDLGLRunloopGB(struct mSDLRenderer* renderer, void* user) {
v->swap(v); v->swap(v);
} }
} }
#endif
void mSDLGLDeinit(struct mSDLRenderer* renderer) { void mSDLGLDeinitGB(struct mSDLRenderer* renderer) {
if (renderer->gl.d.deinit) { if (renderer->gl.d.deinit) {
renderer->gl.d.deinit(&renderer->gl.d); renderer->gl.d.deinit(&renderer->gl.d);
} }
free(renderer->d.outputBuffer); free(renderer->gb.outputBuffer);
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_GL_DeleteContext(renderer->glCtx); SDL_GL_DeleteContext(renderer->glCtx);
#endif #endif
} }
#endif