Skip to content

Commit d07bd46

Browse files
committed
Qt: Improve cleanup flow, fix crashes when exiting with OpenGL renderer
1 parent 65641c7 commit d07bd46

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Other fixes:
5454
- Qt: Fix selecting high tiles in tile and map views (fixes mgba.io/i/3461)
5555
- Qt: Fix some actions disabled in multiplayer staying disabled after closing game
5656
- Qt: Fix unexpected mute when window becomes focused while fast-forwarding
57+
- Qt: Fix crashes when exiting with OpenGL renderer
5758
Misc:
5859
- 3DS: Change title ID to avoid conflict with commercial title (fixes mgba.io/i/3023)
5960
- Core: Handle relative paths for saves, screenshots, etc consistently (fixes mgba.io/i/2826)

src/platform/qt/DisplayGL.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,6 @@ void PainterGL::doStop() {
917917
m_started = false;
918918
dequeueAll(false);
919919
if (m_context) {
920-
if (m_videoProxy) {
921-
m_videoProxy->detach(m_context.get());
922-
}
923920
m_context->setFramebufferHandle(-1);
924921
m_context.reset();
925922
if (m_videoProxy) {

src/platform/qt/Window.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -992,12 +992,7 @@ void Window::gameStopped() {
992992
#endif
993993
}
994994

995-
std::shared_ptr<CoreController> controller;
996-
m_controller.swap(controller);
997-
QTimer::singleShot(0, this, [controller]() {
998-
// Destroy the controller after everything else has cleaned up
999-
Q_UNUSED(controller);
1000-
});
995+
m_cleanupController = std::move(m_controller);
1001996
detachWidget();
1002997
updateTitle();
1003998

@@ -1008,9 +1003,10 @@ void Window::gameStopped() {
10081003
m_scripting->setVideoBackend(nullptr);
10091004
}
10101005
#endif
1011-
m_display.reset();
1006+
m_cleanupDisplay = std::move(m_display);
10121007
close();
10131008
}
1009+
QTimer::singleShot(0, this, &Window::delayedCleanup);
10141010
#ifndef Q_OS_MAC
10151011
showMenu(true);
10161012
#endif
@@ -2360,6 +2356,13 @@ void Window::setLogo() {
23602356
centralWidget()->unsetCursor();
23612357
}
23622358

2359+
void Window::delayedCleanup() {
2360+
// Destroy the controller after everything else has cleaned up, except for the display
2361+
m_cleanupController.reset();
2362+
// The display needs to be cleaned up last so the core can clean up the OpenGL resources
2363+
m_cleanupDisplay.reset();
2364+
}
2365+
23632366
WindowBackground::WindowBackground(QWidget* parent)
23642367
: QWidget(parent)
23652368
{

src/platform/qt/Window.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ private slots:
161161

162162
void setLogo();
163163

164+
void delayedCleanup();
165+
164166
private:
165167
static const int FPS_TIMER_INTERVAL = 2000;
166168
static const int MUST_RESTART_TIMEOUT = 10000;
@@ -266,6 +268,9 @@ private slots:
266268
#ifdef ENABLE_SCRIPTING
267269
std::unique_ptr<ScriptingController> m_scripting;
268270
#endif
271+
272+
std::unique_ptr<QGBA::Display> m_cleanupDisplay;
273+
std::shared_ptr<CoreController> m_cleanupController;
269274
};
270275

271276
class WindowBackground : public QWidget {

0 commit comments

Comments
 (0)