From 77886d4cf437044faf241c011616f2c041a648de Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 22 Jan 2016 20:25:13 -0800 Subject: [PATCH] SDL: Fix crashing on GB game exit --- src/platform/sdl/gl-sdl.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/platform/sdl/gl-sdl.c b/src/platform/sdl/gl-sdl.c index 79a99c266..718eb98ec 100644 --- a/src/platform/sdl/gl-sdl.c +++ b/src/platform/sdl/gl-sdl.c @@ -23,17 +23,18 @@ static void _doViewport(int w, int h, struct VideoBackend* v) { #ifdef M_CORE_GBA static bool mSDLGLInitGBA(struct mSDLRenderer* renderer); static void mSDLGLRunloopGBA(struct mSDLRenderer* renderer, void* user); +static void mSDLGLDeinitGBA(struct mSDLRenderer* renderer); #endif #ifdef M_CORE_GB static bool mSDLGLInitGB(struct mSDLRenderer* renderer); static void mSDLGLRunloopGB(struct mSDLRenderer* renderer, void* user); +static void mSDLGLDeinitGB(struct mSDLRenderer* renderer); #endif -static void mSDLGLDeinit(struct mSDLRenderer* renderer); #ifdef M_CORE_GBA void mSDLGLCreate(struct mSDLRenderer* renderer) { renderer->init = mSDLGLInitGBA; - renderer->deinit = mSDLGLDeinit; + renderer->deinit = mSDLGLDeinitGBA; renderer->runloop = mSDLGLRunloopGBA; } @@ -80,12 +81,22 @@ void mSDLGLRunloopGBA(struct mSDLRenderer* renderer, void* user) { 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 #ifdef M_CORE_GB void mSDLGLCreateGB(struct mSDLRenderer* renderer) { renderer->init = mSDLGLInitGB; - renderer->deinit = mSDLGLDeinit; + renderer->deinit = mSDLGLDeinitGB; renderer->runloop = mSDLGLRunloopGB; } @@ -155,14 +166,14 @@ void mSDLGLRunloopGB(struct mSDLRenderer* renderer, void* user) { v->swap(v); } } -#endif -void mSDLGLDeinit(struct mSDLRenderer* renderer) { +void mSDLGLDeinitGB(struct mSDLRenderer* renderer) { if (renderer->gl.d.deinit) { renderer->gl.d.deinit(&renderer->gl.d); } - free(renderer->d.outputBuffer); + free(renderer->gb.outputBuffer); #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_GL_DeleteContext(renderer->glCtx); #endif } +#endif