Explorar o código

UI: Destroy display when becoming invisible

When a window is made invisible, then visible again, the
obs_display is reused. Turns out, QT destroys the wl_surface
associated with the previewer on Wayland. However, the EGL
surface created on top of this wl_surface is not, and any
attempt to attach a new buffer to it will crash OBS.

Destroy the obs_display when becoming invisible, and when
running as a Wayland client. Also nullify the display
variable on destruction, to avoid subclasses double-freeing
the obs display.
Georges Basile Stavracas Neto %!s(int64=5) %!d(string=hai) anos
pai
achega
60dab2cf1c
Modificáronse 2 ficheiros con 13 adicións e 1 borrados
  1. 12 1
      UI/qt-display.cpp
  2. 1 0
      UI/qt-display.hpp

+ 12 - 1
UI/qt-display.cpp

@@ -6,6 +6,12 @@
 #include <QResizeEvent>
 #include <QShowEvent>
 
+#include <obs-config.h>
+
+#ifdef ENABLE_WAYLAND
+#include <obs-nix-platform.h>
+#endif
+
 static inline long long color_to_int(const QColor &color)
 {
 	auto shift = [&](unsigned val, int shift) {
@@ -33,8 +39,13 @@ OBSQTDisplay::OBSQTDisplay(QWidget *parent, Qt::WindowFlags flags)
 	setAttribute(Qt::WA_NativeWindow);
 
 	auto windowVisible = [this](bool visible) {
-		if (!visible)
+		if (!visible) {
+#ifdef ENABLE_WAYLAND
+			if (obs_get_nix_platform() == OBS_NIX_PLATFORM_WAYLAND)
+				display = nullptr;
+#endif
 			return;
+		}
 
 		if (!display) {
 			CreateDisplay();

+ 1 - 0
UI/qt-display.hpp

@@ -25,6 +25,7 @@ signals:
 public:
 	OBSQTDisplay(QWidget *parent = nullptr,
 		     Qt::WindowFlags flags = Qt::WindowFlags());
+	~OBSQTDisplay() { display = nullptr; }
 
 	virtual QPaintEngine *paintEngine() const override;