Skip to content

Commit

Permalink
qt: unregister Settings' DevicesChanged callback during shutdown
Browse files Browse the repository at this point in the history
fixes a crash on close
  • Loading branch information
shuffle2 committed Jun 3, 2022
1 parent f7f47d3 commit 27dd2c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ void MainWindow::ShutdownControllers()
{
m_hotkey_scheduler->Stop();

Settings::Instance().UnregisterDevicesChangedCallback();

Pad::Shutdown();
Pad::ShutdownGBA();
Keyboard::Shutdown();
Expand Down
7 changes: 6 additions & 1 deletion Source/Core/DolphinQt/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Settings::Settings()
}
});

g_controller_interface.RegisterDevicesChangedCallback([this] {
m_hotplug_callback_handle = g_controller_interface.RegisterDevicesChangedCallback([this] {
if (Host::GetInstance()->IsHostThread())
{
emit DevicesChanged();
Expand All @@ -90,6 +90,11 @@ Settings::Settings()

Settings::~Settings() = default;

void Settings::UnregisterDevicesChangedCallback()
{
g_controller_interface.UnregisterDevicesChangedCallback(m_hotplug_callback_handle);
}

Settings& Settings::Instance()
{
static Settings settings;
Expand Down
7 changes: 6 additions & 1 deletion Source/Core/DolphinQt/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "Core/Config/MainSettings.h"
#include "DiscIO/Enums.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"

namespace Core
{
Expand Down Expand Up @@ -44,6 +45,8 @@ class Settings final : public QObject

~Settings();

void UnregisterDevicesChangedCallback();

static Settings& Instance();
static QSettings& GetQSettings();

Expand Down Expand Up @@ -199,10 +202,12 @@ class Settings final : public QObject
void USBKeyboardConnectionChanged(bool connected);

private:
Settings();

bool m_batch = false;
std::shared_ptr<NetPlay::NetPlayClient> m_client;
std::shared_ptr<NetPlay::NetPlayServer> m_server;
Settings();
ControllerInterface::HotplugCallbackHandle m_hotplug_callback_handle;
};

Q_DECLARE_METATYPE(Core::State);

0 comments on commit 27dd2c4

Please sign in to comment.