From c8bf7c82f78cdd2c335810a8ec22a62e1906c40f Mon Sep 17 00:00:00 2001 From: BeWorld <36823759+BeWorld2018@users.noreply.github.com> Date: Thu, 31 Aug 2023 12:57:31 +0200 Subject: [PATCH 1/3] Add SDL_GameContrllerClose Fix memory leak --- src/platform_sdl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platform_sdl.c b/src/platform_sdl.c index 5fc5e0b..851b19a 100755 --- a/src/platform_sdl.c +++ b/src/platform_sdl.c @@ -418,6 +418,10 @@ int main(int argc, char *argv[]) { system_cleanup(); platform_video_cleanup(); + if (gamepad) { + SDL_GameControllerClose(gamepad); + } + if (sdl_path_assets) { SDL_free(sdl_path_assets); } From 07d8a37afd4250994e466b88ebc380734f4c906b Mon Sep 17 00:00:00 2001 From: BeWorld <36823759+BeWorld2018@users.noreply.github.com> Date: Fri, 1 Sep 2023 10:26:56 +0200 Subject: [PATCH 2/3] Destroy Window and Renderer --- src/platform_sdl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/platform_sdl.c b/src/platform_sdl.c index 851b19a..d2d8146 100755 --- a/src/platform_sdl.c +++ b/src/platform_sdl.c @@ -247,9 +247,6 @@ uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) { return file_store(path, bytes, len); } - - - #if defined(RENDERER_GL) // ---------------------------------------------------- #define PLATFORM_WINDOW_FLAGS SDL_WINDOW_OPENGL SDL_GLContext platform_gl; @@ -271,6 +268,7 @@ uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) { void platform_video_cleanup() { SDL_GL_DeleteContext(platform_gl); + SDL_DestroyWindow(window); } void platform_end_frame() { @@ -299,7 +297,11 @@ uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) { } void platform_video_cleanup() { - + if (screenbuffer) { + SDL_DestroyTexture(screenbuffer); + } + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); } void platform_prepare_frame() { From aa06570a054c4d774fa331715cb1d171c5ed4ff7 Mon Sep 17 00:00:00 2001 From: BeWorld <36823759+BeWorld2018@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:10:24 +0200 Subject: [PATCH 3/3] Move SDL_DestroyWindow in main() --- src/platform_sdl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/platform_sdl.c b/src/platform_sdl.c index d2d8146..cf000bc 100755 --- a/src/platform_sdl.c +++ b/src/platform_sdl.c @@ -268,7 +268,6 @@ uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) { void platform_video_cleanup() { SDL_GL_DeleteContext(platform_gl); - SDL_DestroyWindow(window); } void platform_end_frame() { @@ -301,7 +300,6 @@ uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) { SDL_DestroyTexture(screenbuffer); } SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); } void platform_prepare_frame() { @@ -341,8 +339,6 @@ uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) { #error "Unsupported renderer for platform SDL" #endif - - int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); @@ -420,6 +416,8 @@ int main(int argc, char *argv[]) { system_cleanup(); platform_video_cleanup(); + SDL_DestroyWindow(window); + if (gamepad) { SDL_GameControllerClose(gamepad); }