From e0058c17fffd3fb57ad130fc33e056a8f8e7dfc3 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 5 Apr 2022 14:53:47 +0200 Subject: [PATCH] lr: don't terminate emu on deinit. gl4: buffer wasn't released on term() shared libraries containing gnuc unique symbols are never unloaded on linux, and possibly other platforms. So don't terminate the emulator on deinit and init it only once. Issue #566 gl4: buffer not released on term() was causing crashes or black screen when restarted. --- core/rend/gl4/abuffer.cpp | 2 +- shell/libretro/libretro.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/rend/gl4/abuffer.cpp b/core/rend/gl4/abuffer.cpp index 3462725f5..d1e3b4fb7 100644 --- a/core/rend/gl4/abuffer.cpp +++ b/core/rend/gl4/abuffer.cpp @@ -393,7 +393,7 @@ void termABuffer() glDeleteVertexArrays(1, &g_quadVertexArray); g_quadVertexArray = 0; } - g_quadIndexBuffer.reset(); + g_quadBuffer.reset(); g_quadIndexBuffer.reset(); glcache.DeleteProgram(g_abuffer_final_shader.program); g_abuffer_final_shader.program = 0; diff --git a/shell/libretro/libretro.cpp b/shell/libretro/libretro.cpp index a5dec7b44..5bee06671 100644 --- a/shell/libretro/libretro.cpp +++ b/shell/libretro/libretro.cpp @@ -289,6 +289,8 @@ static void retro_keyboard_event(bool down, unsigned keycode, uint32_t character // Now comes the interesting stuff void retro_init() { + static bool emuInited; + // Logging struct retro_log_callback log; if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) @@ -322,6 +324,12 @@ void retro_init() os_InstallFaultHandler(); MapleConfigMap::UpdateVibration = updateVibration; + +#if defined(__GNUC__) && !defined(_WIN32) + if (!emuInited) +#endif + emu.init(); + emuInited = true; } void retro_deinit() @@ -335,6 +343,12 @@ void retro_deinit() std::lock_guard lock(mtx_serialization); } os_UninstallFaultHandler(); + +#if defined(__GNUC__) && !defined(_WIN32) + _vmem_release(); +#else + emu.term(); +#endif libretro_supports_bitmasks = false; categoriesSupported = false; platformIsDreamcast = true; @@ -1913,13 +1927,11 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i void retro_unload_game() { INFO_LOG(COMMON, "Flycast unloading game"); - emu.stop(); + emu.unloadGame(); game_data.clear(); disk_paths.clear(); disk_labels.clear(); blankVmus(); - - emu.term(); }