Qt: Fix IOWindow keeping a shared ptr to devices even after them being removed by the ControllerInterface

this prevented some devices from being recreated correctly, as they were exclusive (e.g. DInput Joysticks)

This is achieved by calling Settings::ReleaseDevices(), which releases all the UI devices shared ptrs.
If we are the host (Qt) thread, DevicesChanged() is now called in line, to avoid devices being hanged onto by the UI.
For this, I had to add a method to check whether we are the Host Thread to Qt.

Avoid calling ControllerInterface::RefreshDevices() from the CPU thread if the emulation is running
and we manually refresh devices from Qt, as that is not necessary anymore.

Refactored the way IOWindow lists devices to make it clearer and hold onto disconnected devices.
There were so many issues with the previous code:
-Devices changes would not be reflected until the window was re-opened
-If there was no default device, it would fail to select the device at index 0
-It could have crashed if we had 0 devices
-The default device was not highlighted as such
This commit is contained in:
Filoppi
2021-05-21 01:33:38 +03:00
parent a77e3b4a9b
commit 83ea16f402
10 changed files with 130 additions and 27 deletions

View File

@ -789,7 +789,7 @@ void MainWindow::TogglePause()
void MainWindow::OnStopComplete()
{
m_stop_requested = false;
HideRenderWidget();
HideRenderWidget(true, m_exit_requested);
#ifdef USE_DISCORD_PRESENCE
if (!m_netplay_dialog->isVisible())
Discord::UpdateDiscordPresence();
@ -1099,7 +1099,7 @@ void MainWindow::ShowRenderWidget()
}
}
void MainWindow::HideRenderWidget(bool reinit)
void MainWindow::HideRenderWidget(bool reinit, bool is_exit)
{
if (m_rendering_to_main)
{
@ -1136,7 +1136,9 @@ void MainWindow::HideRenderWidget(bool reinit)
// The controller interface will still be registered to the old render widget, if the core
// has booted. Therefore, we should re-bind it to the main window for now. When the core
// is next started, it will be swapped back to the new render widget.
g_controller_interface.ChangeWindow(GetWindowSystemInfo(windowHandle()).render_window);
g_controller_interface.ChangeWindow(GetWindowSystemInfo(windowHandle()).render_window,
is_exit ? ControllerInterface::WindowChangeReason::Exit :
ControllerInterface::WindowChangeReason::Other);
}
}