Qt: Defer destroying the CoreController until after the CoreController::stopping slots finish

This commit is contained in:
Vicki Pfau 2025-01-12 06:14:10 -08:00
parent 762a54a388
commit 6be223d84a
1 changed files with 6 additions and 6 deletions
src/platform/qt

View File

@ -972,7 +972,12 @@ void Window::gameStopped() {
#endif
}
m_controller.reset();
std::shared_ptr<CoreController> controller;
m_controller.swap(controller);
QTimer::singleShot(0, this, [controller]() {
// Destroy the controller after everything else has cleaned up
Q_UNUSED(controller);
});
detachWidget();
updateTitle();
@ -2155,11 +2160,6 @@ void Window::setController(CoreController* controller, const QString& fname) {
connect(m_controller.get(), &CoreController::started, this, &Window::gameStarted);
connect(m_controller.get(), &CoreController::started, GBAApp::app(), &GBAApp::suspendScreensaver);
connect(m_controller.get(), &CoreController::stopping, this, &Window::gameStopped);
{
connect(m_controller.get(), &CoreController::stopping, [this]() {
m_controller.reset();
});
}
connect(m_controller.get(), &CoreController::stopping, GBAApp::app(), &GBAApp::resumeScreensaver);
connect(m_controller.get(), &CoreController::paused, this, &Window::updateFrame);