Browse Source

UI: Fix crash when toggling volume control mode

The toggleControlLayoutAction (change between horizontal and vertical
display mode) deletes and re-recreates the volume controls, meaning we
were writing to freed memory. This is a kind of hacky fix but it's the
only action we need to be concerned with for now.
Richard Stanway 3 years ago
parent
commit
c64997ed80
1 changed files with 5 additions and 2 deletions
  1. 5 2
      UI/window-basic-main.cpp

+ 5 - 2
UI/window-basic-main.cpp

@@ -3509,8 +3509,11 @@ void OBSBasic::VolControlContextMenu()
 	popup.addAction(&filtersAction);
 	popup.addAction(&propertiesAction);
 	popup.addAction(&advPropAction);
-	popup.exec(QCursor::pos());
-	vol->SetContextMenu(nullptr);
+
+	// toggleControlLayoutAction deletes and re-creates the volume controls
+	// meaning that "vol" would be pointing to freed memory.
+	if (popup.exec(QCursor::pos()) != &toggleControlLayoutAction)
+		vol->SetContextMenu(nullptr);
 }
 
 void OBSBasic::on_hMixerScrollArea_customContextMenuRequested()