window: undo last commit (was a trainwreck). explicitly close child windows to avoid GL issues. fix bug with window parenting in second multiplayer instances.

This commit is contained in:
Arisotura
2025-06-28 12:37:53 +02:00
parent baad893bc0
commit 2499ec36c2
3 changed files with 33 additions and 13 deletions

View File

@ -204,7 +204,7 @@ void EmuInstance::createWindow(int id)
if (windowList[id]) if (windowList[id])
return; return;
MainWindow* win = new MainWindow(id, this, topWindow); MainWindow* win = new MainWindow(id, this, mainWindow ? mainWindow : topWindow);
if (!topWindow) topWindow = win; if (!topWindow) topWindow = win;
if (!mainWindow) mainWindow = win; if (!mainWindow) mainWindow = win;
windowList[id] = win; windowList[id] = win;

View File

@ -809,18 +809,6 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
if (windowID == 0)
emuInstance->saveEnabledWindows();
else
saveEnabled(false);
QByteArray geom = saveGeometry();
QByteArray enc = geom.toBase64(QByteArray::Base64Encoding);
windowCfg.SetString("Geometry", enc.toStdString());
Config::Save();
emuInstance->deleteWindow(windowID, false);
if (hasMenu) if (hasMenu)
{ {
delete[] actScreenAspectTop; delete[] actScreenAspectTop;
@ -841,6 +829,36 @@ void MainWindow::saveEnabled(bool enabled)
enabledSaved = true; enabledSaved = true;
} }
void MainWindow::closeEvent(QCloseEvent* event)
{
if (emuInstance)
{
if (windowID == 0)
emuInstance->saveEnabledWindows();
else
saveEnabled(false);
}
// explicitly close children windows, so the OpenGL contexts get closed properly
auto childwins = findChildren<MainWindow *>(nullptr, Qt::FindDirectChildrenOnly);
for (auto child : childwins)
child->close();
if (!emuInstance) return;
QByteArray geom = saveGeometry();
QByteArray enc = geom.toBase64(QByteArray::Base64Encoding);
windowCfg.SetString("Geometry", enc.toStdString());
Config::Save();
emuInstance->deleteWindow(windowID, false);
// emuInstance may be deleted
// prevent use after free from us
emuInstance = nullptr;
QMainWindow::closeEvent(event);
}
void MainWindow::createScreenPanel() void MainWindow::createScreenPanel()
{ {
if (panel) delete panel; if (panel) delete panel;

View File

@ -242,6 +242,8 @@ private slots:
void onScreenEmphasisToggled(); void onScreenEmphasisToggled();
private: private:
virtual void closeEvent(QCloseEvent* event) override;
QStringList currentROM; QStringList currentROM;
QStringList currentGBAROM; QStringList currentGBAROM;
QList<QString> recentFileList; QList<QString> recentFileList;