FreeLook: Remove ConfigChangedCallback on shutdown

This commit is contained in:
Dentomologist 2025-04-25 15:11:53 -07:00
parent 9db4067957
commit d0dc8ae5e1
3 changed files with 19 additions and 5 deletions

View file

@ -3,6 +3,8 @@
#include "Core/FreeLookConfig.h"
#include <optional>
#include "Core/AchievementManager.h"
#include "Core/CPUThreadConfigCallback.h"
#include "Core/Config/AchievementSettings.h"
@ -14,7 +16,8 @@ namespace FreeLook
{
static Config s_config;
static Config s_active_config;
static bool s_has_registered_callback = false;
static std::optional<CPUThreadConfigCallback::ConfigChangedCallbackID>
s_config_changed_callback_id = std::nullopt;
Config& GetConfig()
{
@ -39,14 +42,23 @@ Config::Config()
void Config::Refresh()
{
if (!s_has_registered_callback)
if (!s_config_changed_callback_id.has_value())
{
s_config_changed_callback_id =
CPUThreadConfigCallback::AddConfigChangedCallback([] { s_config.Refresh(); });
s_has_registered_callback = true;
}
camera_config.control_type = ::Config::Get(::Config::FL1_CONTROL_TYPE);
enabled = ::Config::Get(::Config::FREE_LOOK_ENABLED) &&
!AchievementManager::GetInstance().IsHardcoreModeActive();
}
void Config::Shutdown()
{
if (!s_config_changed_callback_id.has_value())
return;
CPUThreadConfigCallback::RemoveConfigChangedCallback(*s_config_changed_callback_id);
s_config_changed_callback_id.reset();
}
} // namespace FreeLook

View file

@ -27,6 +27,7 @@ struct Config final
{
Config();
void Refresh();
void Shutdown();
CameraConfig camera_config;
bool enabled;

View file

@ -325,8 +325,9 @@ InputConfig* GetInputConfig()
void Shutdown()
{
s_config.UnregisterHotplugCallback();
s_config.ClearControllers();
GetConfig().Shutdown();
}
void Initialize()