diff --git a/src/duckstation-libretro/libretro_host_interface.cpp b/src/duckstation-libretro/libretro_host_interface.cpp index 802a783c8..d30d0eadf 100644 --- a/src/duckstation-libretro/libretro_host_interface.cpp +++ b/src/duckstation-libretro/libretro_host_interface.cpp @@ -36,6 +36,7 @@ retro_input_state_t g_retro_input_state_callback; static retro_log_callback s_libretro_log_callback = {}; static bool s_libretro_log_callback_valid = false; +static bool s_libretro_log_callback_registered = false; static void LibretroLogCallback(void* pUserParam, const char* channelName, const char* functionName, LOGLEVEL level, const char* message) @@ -64,8 +65,16 @@ void LibretroHostInterface::InitLogging() { s_libretro_log_callback_valid = g_retro_environment_callback(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &s_libretro_log_callback); + if (s_libretro_log_callback_registered) + { + Log::UnregisterCallback(LibretroLogCallback, nullptr); + s_libretro_log_callback_registered = false; + } if (s_libretro_log_callback_valid) + { Log::RegisterCallback(LibretroLogCallback, nullptr); + s_libretro_log_callback_registered = true; + } } bool LibretroHostInterface::Initialize() diff --git a/src/duckstation-libretro/main.cpp b/src/duckstation-libretro/main.cpp index 56b1e00da..41d6f4e5d 100644 --- a/src/duckstation-libretro/main.cpp +++ b/src/duckstation-libretro/main.cpp @@ -121,16 +121,12 @@ RETRO_API size_t retro_get_memory_size(unsigned id) RETRO_API void retro_set_environment(retro_environment_t f) { - static bool core_options_set = false; - g_retro_environment_callback = f; - if (!core_options_set) - { - core_options_set = true; - g_libretro_host_interface.InitLogging(); - if (!g_libretro_host_interface.SetCoreOptions()) - Log_WarningPrintf("Failed to set core options, settings will not be changeable."); - } + + if (!g_libretro_host_interface.SetCoreOptions()) + Log_WarningPrintf("Failed to set core options, settings will not be changeable."); + + g_libretro_host_interface.InitLogging(); } RETRO_API void retro_set_video_refresh(retro_video_refresh_t f)