Browse Source

UI: Lock graphics context when adding new sources

Prevents a potential cross-lock deadlock.  The UI thread would lock the
scene's mutex in obs_scene_atomic_update, then the item would lock the
graphics context to create a texture.  Meanwhile in the video thread, it
could lock the graphics context in the render loop, then lock the
scene's mutex when rendering.  When doing anything graphics-related, the
graphics context is always supposed to be locked before the scene's
mutex is supposed to be locked (it's designed that way), and the
obs_scene_atomic_update would just bypass that.
jp9000 8 years ago
parent
commit
8f43934be6
1 changed files with 6 additions and 0 deletions
  1. 6 0
      UI/window-basic-source-select.cpp

+ 6 - 0
UI/window-basic-source-select.cpp

@@ -137,7 +137,10 @@ static void AddExisting(const char *name, bool visible, bool duplicate)
 		AddSourceData data;
 		data.source = source;
 		data.visible = visible;
+
+		obs_enter_graphics();
 		obs_scene_atomic_update(scene, AddSource, &data);
+		obs_leave_graphics();
 
 		obs_source_release(source);
 	}
@@ -165,7 +168,10 @@ bool AddNew(QWidget *parent, const char *id, const char *name,
 			AddSourceData data;
 			data.source = source;
 			data.visible = visible;
+
+			obs_enter_graphics();
 			obs_scene_atomic_update(scene, AddSource, &data);
+			obs_leave_graphics();
 
 			newSource = source;