From f8d415afbee4873a3eb15c7e77833fbee6c87871 Mon Sep 17 00:00:00 2001 From: Kurt Kartaltepe Date: Sun, 15 May 2022 17:54:24 -0700 Subject: [PATCH] UI: Close display before native surfaces This hooks the platform specific events in order to close the obs display more accurately. Earlier attempts on hooking visiblity, but Qt does not ensure that visibility is changed before the surface is destroyed. So we ended up racing with the EGL driver and on some drivers if you lose the race they hang. Also only force display creation if the display is actually visible. When a source type is not video/drawable (or is missing) this would force the display to be created for the blank window and also hang. Finally force closure of the preview displays during scene cleanup to avoid similar ordering issues in Qt. Qt has even less order guarentees during close and we are sure that displays are no longer needed at this point in the UI. --- UI/qt-display.cpp | 8 +++++++- UI/qt-display.hpp | 1 + UI/window-basic-main.cpp | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/UI/qt-display.cpp b/UI/qt-display.cpp index 1352df6e6..07c663dfd 100644 --- a/UI/qt-display.cpp +++ b/UI/qt-display.cpp @@ -42,6 +42,9 @@ protected: else mTimerId = startTimer(67); // Arbitrary break; + case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: + display->DestroyDisplay(); + break; case QEvent::Expose: createOBSDisplay(); break; @@ -52,7 +55,10 @@ protected: return result; } - void timerEvent(QTimerEvent *) { createOBSDisplay(true); } + void timerEvent(QTimerEvent *) + { + createOBSDisplay(display->isVisible()); + } private: void createOBSDisplay(bool force = false) diff --git a/UI/qt-display.hpp b/UI/qt-display.hpp index 1edba68de..4c3b3c92b 100644 --- a/UI/qt-display.hpp +++ b/UI/qt-display.hpp @@ -43,6 +43,7 @@ public: void SetDisplayBackgroundColor(const QColor &color); void UpdateDisplayBackgroundColor(); void CreateDisplay(bool force = false); + void DestroyDisplay() { display = nullptr; }; void OnMove(); void OnDisplayChange(); diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index e18a2a541..af3ca29c3 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -4707,6 +4707,10 @@ void OBSBasic::closeEvent(QCloseEvent *event) delete extraBrowsers; + ui->preview->DestroyDisplay(); + if (program) + program->DestroyDisplay(); + config_set_string(App()->GlobalConfig(), "BasicWindow", "DockState", saveState().toBase64().constData());