Browse Source

UI: Add timer to NewYouTubeAppDock()

CEF apparently doesn't like it and is unable to handle when you
destroy/recreate CEF instances very quickly, so... let's just put a
timer on this insanely terrible function. I guess. Whatever.
Lain 2 years ago
parent
commit
a44ab2efcc
2 changed files with 15 additions and 0 deletions
  1. 14 0
      UI/window-basic-main.cpp
  2. 1 0
      UI/window-basic-main.hpp

+ 14 - 0
UI/window-basic-main.cpp

@@ -8484,11 +8484,25 @@ YouTubeAppDock *OBSBasic::GetYouTubeAppDock()
 	return youtubeAppDock;
 }
 
+#ifndef SEC_TO_NSEC
+#define SEC_TO_NSEC 1000000000
+#endif
+
 void OBSBasic::NewYouTubeAppDock()
 {
 	if (!cef_js_avail)
 		return;
 
+	/* make sure that the youtube app dock can't be immediately recreated.
+	 * dumb hack. blame chromium. or this particular dock. or both. if CEF
+	 * creates/destroys/creates a widget too quickly it can lead to a
+	 * crash. */
+	uint64_t ts = os_gettime_ns();
+	if ((ts - lastYouTubeAppDockCreationTime) < (5ULL * SEC_TO_NSEC))
+		return;
+
+	lastYouTubeAppDockCreationTime = ts;
+
 	if (youtubeAppDock)
 		RemoveDockWidget(youtubeAppDock->objectName());
 

+ 1 - 0
UI/window-basic-main.hpp

@@ -267,6 +267,7 @@ private:
 	QPointer<QDockWidget> statsDock;
 #ifdef YOUTUBE_ENABLED
 	QPointer<YouTubeAppDock> youtubeAppDock;
+	uint64_t lastYouTubeAppDockCreationTime = 0;
 #endif
 	QPointer<OBSAbout> about;
 	QPointer<OBSMissingFiles> missDialog;