Selaa lähdekoodia

UI: Fix removing wrong scene from list

RemoveScene would always remove the currently selected item from the
scenes list, even if that item didn't reference the actual scene being
removed; finding the proper item via its OBSRef fixes this issue.

How to reproduce the original issue:
Create two scenes "a" and "b", set a hotkey for switching to scene "a",
select scene "b" and press the remove scene button, then while the
confirmation dialog is up press the hotkey while the UI is out of focus.
The active scene should have switched to "a", while the dialog still
displays "b" as its target; now confirm the removal of "b". Note how "a"
was removed from the scenes list instead.

Reported at https://obsproject.com/mantis/view.php?id=333
Palana 10 vuotta sitten
vanhempi
sitoutus
80b20abde2
1 muutettua tiedostoa jossa 13 lisäystä ja 5 poistoa
  1. 13 5
      obs/window-basic-main.cpp

+ 13 - 5
obs/window-basic-main.cpp

@@ -1374,14 +1374,22 @@ void OBSBasic::AddScene(OBSSource source)
 
 void OBSBasic::RemoveScene(OBSSource source)
 {
-	const char *name = obs_source_get_name(source);
+	obs_scene_t *scene = obs_scene_from_source(source);
+
+	QListWidgetItem *sel = nullptr;
+	int count = ui->scenes->count();
+	for (int i = 0; i < count; i++) {
+		auto item = ui->scenes->item(i);
+		auto cur_scene = GetOBSRef<OBSScene>(item);
+		if (cur_scene != scene)
+			continue;
 
-	QListWidgetItem *sel = ui->scenes->currentItem();
-	QList<QListWidgetItem*> items = ui->scenes->findItems(QT_UTF8(name),
-			Qt::MatchExactly);
+		sel = item;
+		break;
+	}
 
 	if (sel != nullptr) {
-		if (items.contains(sel))
+		if (sel == ui->scenes->currentItem())
 			ClearListItems(ui->sources);
 		delete sel;
 	}