From 0d55ab2bb6093ae0a4a72e65c657deb3dbf61d60 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 29 Jan 2019 14:03:09 -0800 Subject: [PATCH] Switch: Fix final cleanup (fixes #1283) --- CHANGES | 2 + src/platform/switch/main.c | 89 ++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/CHANGES b/CHANGES index e19a2e9bd..79d9af178 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ 0.7.1: (Future) +Bugfixes: + - Switch: Fix final cleanup (fixes mgba.io/i/1283) Misc: - GBA Video: Improve sprite cycle counting (fixes mgba.io/i/1274) diff --git a/src/platform/switch/main.c b/src/platform/switch/main.c index a6e8d9941..e344ff44d 100644 --- a/src/platform/switch/main.c +++ b/src/platform/switch/main.c @@ -100,63 +100,64 @@ static enum ScreenMode { } screenMode = SM_PA; static bool initEgl() { - s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (!s_display) { - goto _fail0; - } + s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (!s_display) { + goto _fail0; + } - eglInitialize(s_display, NULL, NULL); + eglInitialize(s_display, NULL, NULL); - EGLConfig config; - EGLint numConfigs; - static const EGLint attributeList[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_NONE - }; - eglChooseConfig(s_display, attributeList, &config, 1, &numConfigs); - if (!numConfigs) { - goto _fail1; - } + EGLConfig config; + EGLint numConfigs; + static const EGLint attributeList[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_NONE + }; + eglChooseConfig(s_display, attributeList, &config, 1, &numConfigs); + if (!numConfigs) { + goto _fail1; + } - s_surface = eglCreateWindowSurface(s_display, config, nwindowGetDefault(), NULL); - if (!s_surface) { - goto _fail1; - } + s_surface = eglCreateWindowSurface(s_display, config, nwindowGetDefault(), NULL); + if (!s_surface) { + goto _fail1; + } EGLint contextAttributeList[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE }; - s_context = eglCreateContext(s_display, config, EGL_NO_CONTEXT, contextAttributeList); - if (!s_context) { - goto _fail2; - } + s_context = eglCreateContext(s_display, config, EGL_NO_CONTEXT, contextAttributeList); + if (!s_context) { + goto _fail2; + } - eglMakeCurrent(s_display, s_surface, s_surface, s_context); - return true; + eglMakeCurrent(s_display, s_surface, s_surface, s_context); + return true; _fail2: - eglDestroySurface(s_display, s_surface); - s_surface = NULL; + eglDestroySurface(s_display, s_surface); + s_surface = NULL; _fail1: - eglTerminate(s_display); - s_display = NULL; + eglTerminate(s_display); + s_display = NULL; _fail0: - return false; + return false; } static void deinitEgl() { - if (s_display) { - if (s_context) { - eglDestroyContext(s_display, s_context); - } - if (s_surface) { - eglDestroySurface(s_display, s_surface); - } - eglTerminate(s_display); - } + if (s_display) { + eglMakeCurrent(s_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (s_context) { + eglDestroyContext(s_display, s_context); + } + if (s_surface) { + eglDestroySurface(s_display, s_surface); + } + eglTerminate(s_display); + } } static void _mapKey(struct mInputMap* map, uint32_t binding, int nativeKey, enum GBAKey key) { @@ -726,8 +727,14 @@ int main(int argc, char* argv[]) { mGUIRunloop(&runner); } + mGUIDeinit(&runner); + + audoutStopAudioOut(); + GUIFontDestroy(font); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glDeleteBuffers(1, &pbo); glDeleteTextures(1, &tex);