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
This commit is contained in:
Palana 2015-09-24 10:11:38 +02:00
parent ecb8c2c045
commit 80b20abde2

View file

@ -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 = ui->scenes->currentItem();
QList<QListWidgetItem*> items = ui->scenes->findItems(QT_UTF8(name),
Qt::MatchExactly);
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;
sel = item;
break;
}
if (sel != nullptr) {
if (items.contains(sel))
if (sel == ui->scenes->currentItem())
ClearListItems(ui->sources);
delete sel;
}