mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-29 22:20:48 +00:00
Qt: Fix device notification registration segfault
The main window does not exist if we boot with no-gui
This commit is contained in:
parent
f1f85335a7
commit
10d038e43f
@ -76,10 +76,7 @@ gui_application::~gui_application()
|
|||||||
discord::shutdown();
|
discord::shutdown();
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (m_device_notification_handle && !UnregisterDeviceNotification(m_device_notification_handle))
|
unregister_device_notification();
|
||||||
{
|
|
||||||
gui_log.error("UnregisterDeviceNotification() failed: %s", fmt::win_error{GetLastError(), nullptr});
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,17 +202,9 @@ bool gui_application::Init()
|
|||||||
#ifdef _WIN32 // Currently only needed for raw mouse input on windows
|
#ifdef _WIN32 // Currently only needed for raw mouse input on windows
|
||||||
installNativeEventFilter(&m_native_event_filter);
|
installNativeEventFilter(&m_native_event_filter);
|
||||||
|
|
||||||
// Enable usb device hotplug events
|
if (m_main_window)
|
||||||
// Currently only needed for hotplug on windows, as libusb handles other platforms
|
|
||||||
DEV_BROADCAST_DEVICEINTERFACE notification_filter {};
|
|
||||||
notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
|
|
||||||
notification_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
|
|
||||||
notification_filter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
|
|
||||||
|
|
||||||
m_device_notification_handle = RegisterDeviceNotification(reinterpret_cast<HWND>(m_main_window->winId()), ¬ification_filter, DEVICE_NOTIFY_WINDOW_HANDLE);
|
|
||||||
if (!m_device_notification_handle )
|
|
||||||
{
|
{
|
||||||
gui_log.error("RegisterDeviceNotification() failed: %s", fmt::win_error{GetLastError(), nullptr});
|
register_device_notification(m_main_window->winId());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -491,11 +480,26 @@ std::unique_ptr<gs_frame> gui_application::get_gs_frame()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_game_window = frame;
|
m_game_window = frame;
|
||||||
|
ensure(m_game_window);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (!m_show_gui)
|
||||||
|
{
|
||||||
|
register_device_notification(m_game_window->winId());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
connect(m_game_window, &gs_frame::destroyed, this, [this]()
|
connect(m_game_window, &gs_frame::destroyed, this, [this]()
|
||||||
{
|
{
|
||||||
gui_log.notice("gui_application: Deleting old game window");
|
gui_log.notice("gui_application: Deleting old game window");
|
||||||
m_game_window = nullptr;
|
m_game_window = nullptr;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (!m_show_gui)
|
||||||
|
{
|
||||||
|
unregister_device_notification();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
|
|
||||||
return std::unique_ptr<gs_frame>(frame);
|
return std::unique_ptr<gs_frame>(frame);
|
||||||
@ -1234,3 +1238,40 @@ bool gui_application::native_event_filter::nativeEventFilter([[maybe_unused]] co
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
void gui_application::register_device_notification(WId window_id)
|
||||||
|
{
|
||||||
|
if (m_device_notification_handle) return;
|
||||||
|
|
||||||
|
gui_log.notice("Registering device notifications...");
|
||||||
|
|
||||||
|
// Enable usb device hotplug events
|
||||||
|
// Currently only needed for hotplug on windows, as libusb handles other platforms
|
||||||
|
DEV_BROADCAST_DEVICEINTERFACE notification_filter {};
|
||||||
|
notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
|
||||||
|
notification_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
|
||||||
|
notification_filter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
|
||||||
|
|
||||||
|
m_device_notification_handle = RegisterDeviceNotification(reinterpret_cast<HWND>(window_id), ¬ification_filter, DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||||
|
if (!m_device_notification_handle )
|
||||||
|
{
|
||||||
|
gui_log.error("RegisterDeviceNotification() failed: %s", fmt::win_error{GetLastError(), nullptr});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_application::unregister_device_notification()
|
||||||
|
{
|
||||||
|
if (m_device_notification_handle)
|
||||||
|
{
|
||||||
|
gui_log.notice("Unregistering device notifications...");
|
||||||
|
|
||||||
|
if (!UnregisterDeviceNotification(m_device_notification_handle))
|
||||||
|
{
|
||||||
|
gui_log.error("UnregisterDeviceNotification() failed: %s", fmt::win_error{GetLastError(), nullptr});
|
||||||
|
}
|
||||||
|
|
||||||
|
m_device_notification_handle = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -121,9 +121,13 @@ private:
|
|||||||
u64 m_pause_delayed_tag = 0;
|
u64 m_pause_delayed_tag = 0;
|
||||||
typename Emulator::stop_counter_t m_emu_focus_out_emulation_id{};
|
typename Emulator::stop_counter_t m_emu_focus_out_emulation_id{};
|
||||||
bool m_is_pause_on_focus_loss_active = false;
|
bool m_is_pause_on_focus_loss_active = false;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
void register_device_notification(WId window_id);
|
||||||
|
void unregister_device_notification();
|
||||||
HDEVNOTIFY m_device_notification_handle {};
|
HDEVNOTIFY m_device_notification_handle {};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void OnChangeStyleSheetRequest();
|
void OnChangeStyleSheetRequest();
|
||||||
void OnShortcutChange();
|
void OnShortcutChange();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user