Qt: Defer application quit on window close

Fixes Mac builds crashing when the Metal renderer tries to clear the
layer on a non-existant window.
This commit is contained in:
Stenzek 2023-02-04 18:35:05 +10:00 committed by refractionpcsx2
parent 5c67438925
commit c8d53253d2
1 changed files with 13 additions and 4 deletions

View File

@ -1932,6 +1932,7 @@ void MainWindow::onVMStopped()
// If we're closing or in batch mode, quit the whole application now.
if (m_is_closing || QtHost::InBatchMode())
{
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 1);
QCoreApplication::quit();
return;
}
@ -1975,16 +1976,24 @@ void MainWindow::showEvent(QShowEvent* event)
void MainWindow::closeEvent(QCloseEvent* event)
{
if (!requestShutdown(true, true, EmuConfig.SaveStateOnShutdown))
// If there's no VM, we can just exit as normal.
if (!s_vm_valid)
{
event->ignore();
QMainWindow::closeEvent(event);
return;
}
// But if there is, we have to cancel the action, regardless of whether we ended exiting
// or not. The window still needs to be visible while GS is shutting down.
event->ignore();
// Exit cancelled?
if (!requestShutdown(true, true, EmuConfig.SaveStateOnShutdown))
return;
// Application will be exited in VM stopped handler.
saveStateToConfig();
m_is_closing = true;
QMainWindow::closeEvent(event);
}
static QString getFilenameFromMimeData(const QMimeData* md)