Skip to content

Commit

Permalink
UI: Close display before native surfaces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kkartaltepe authored and jp9000 committed May 28, 2022
1 parent 29759ef commit f8d415a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion UI/qt-display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class SurfaceEventFilter : public QObject {
else
mTimerId = startTimer(67); // Arbitrary
break;
case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed:
display->DestroyDisplay();
break;
case QEvent::Expose:
createOBSDisplay();
break;
Expand All @@ -52,7 +55,10 @@ class SurfaceEventFilter : public QObject {
return result;
}

void timerEvent(QTimerEvent *) { createOBSDisplay(true); }
void timerEvent(QTimerEvent *)
{
createOBSDisplay(display->isVisible());
}

private:
void createOBSDisplay(bool force = false)
Expand Down
1 change: 1 addition & 0 deletions UI/qt-display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class OBSQTDisplay : public QWidget {
void SetDisplayBackgroundColor(const QColor &color);
void UpdateDisplayBackgroundColor();
void CreateDisplay(bool force = false);
void DestroyDisplay() { display = nullptr; };

void OnMove();
void OnDisplayChange();
Expand Down
4 changes: 4 additions & 0 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit f8d415a

Please sign in to comment.