Selaa lähdekoodia

UI: Don't create obs_display when QTToGSWindow fails

Right after showing the OBSQTDisplay widget, it may happen that a
wl_surface is not yet created and attached to the window. When this
happens, creating the OBS display results in a crash.

Make QTToGSWindow return a boolean, indicating success or failure, and
don't create the OBS display on failure.
Georges Basile Stavracas Neto 5 vuotta sitten
vanhempi
sitoutus
b71498e8ab
3 muutettua tiedostoa jossa 8 lisäystä ja 3 poistoa
  1. 2 1
      UI/qt-display.cpp
  2. 5 1
      UI/qt-wrappers.cpp
  3. 1 1
      UI/qt-wrappers.hpp

+ 2 - 1
UI/qt-display.cpp

@@ -100,7 +100,8 @@ void OBSQTDisplay::CreateDisplay()
 	info.format = GS_BGRA;
 	info.zsformat = GS_ZS_NONE;
 
-	QTToGSWindow(windowHandle(), info.window);
+	if (!QTToGSWindow(windowHandle(), info.window))
+		return;
 
 	display = obs_display_create(&info, backgroundColor);
 

+ 5 - 1
UI/qt-wrappers.cpp

@@ -113,8 +113,10 @@ void OBSMessageBox::critical(QWidget *parent, const QString &title,
 	mb.exec();
 }
 
-void QTToGSWindow(QWindow *window, gs_window &gswindow)
+bool QTToGSWindow(QWindow *window, gs_window &gswindow)
 {
+	bool success = true;
+
 #ifdef _WIN32
 	gswindow.hwnd = (HWND)window->winId();
 #elif __APPLE__
@@ -132,10 +134,12 @@ void QTToGSWindow(QWindow *window, gs_window &gswindow)
 			QGuiApplication::platformNativeInterface();
 		gswindow.display =
 			native->nativeResourceForWindow("surface", window);
+		success = gswindow.display != nullptr;
 		break;
 #endif
 	}
 #endif
+	return success;
 }
 
 uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods)

+ 1 - 1
UI/qt-wrappers.hpp

@@ -57,7 +57,7 @@ public:
 
 void OBSErrorBox(QWidget *parent, const char *msg, ...);
 
-void QTToGSWindow(QWindow *window, gs_window &gswindow);
+bool QTToGSWindow(QWindow *window, gs_window &gswindow);
 
 uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods);