Skip to content

Commit

Permalink
UI: Fix selecting correct transition when deleting
Browse files Browse the repository at this point in the history
When deleting a transition, it would sometimes select the one that
replaces it, which could be the separator.  This would cause undefined
behavior.  This fixes it so that it selects either the one that replaces
it (if a valid one replaces it), or the transition at the bottom of the
known list and not the separator.
  • Loading branch information
jp9000 committed Oct 6, 2020
1 parent da8547c commit 3486c0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
28 changes: 22 additions & 6 deletions UI/window-basic-main-transitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ void OBSBasic::InitDefaultTransitions()
ui->transitions->blockSignals(false);
}

int OBSBasic::AddTransitionBeforeSeparator(const QString &name,
obs_source_t *source)
int OBSBasic::TransitionCount()
{
int idx = -1;

int idx = 0;
for (int i = 0; i < ui->transitions->count(); i++) {
QVariant v = ui->transitions->itemData(i);
if (!v.toString().isEmpty()) {
Expand All @@ -115,11 +113,21 @@ int OBSBasic::AddTransitionBeforeSeparator(const QString &name,
}
}

/* should always have at least fade and cut due to them being
* defaults */
assert(idx != 0);
return idx - 1; /* remove separator from equation */
}

int OBSBasic::AddTransitionBeforeSeparator(const QString &name,
obs_source_t *source)
{
int idx = TransitionCount();
ui->transitions->blockSignals(true);
ui->transitions->insertItem(idx - 1, name,
ui->transitions->insertItem(idx, name,
QVariant::fromValue(OBSSource(source)));
ui->transitions->blockSignals(false);
return idx - 1;
return idx;
}

void OBSBasic::AddQuickTransitionHotkey(QuickTransition *qt)
Expand Down Expand Up @@ -577,7 +585,15 @@ void OBSBasic::on_transitionRemove_clicked()
}
}

ui->transitions->blockSignals(true);
ui->transitions->removeItem(idx);
ui->transitions->setCurrentIndex(-1);
ui->transitions->blockSignals(false);

int bottomIdx = TransitionCount() - 1;
if (idx > bottomIdx)
idx = bottomIdx;
ui->transitions->setCurrentIndex(idx);

if (api)
api->on_event(OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED);
Expand Down
1 change: 1 addition & 0 deletions UI/window-basic-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ class OBSBasic : public OBSMainWindow {

void CreateProgramDisplay();
void CreateProgramOptions();
int TransitionCount();
int AddTransitionBeforeSeparator(const QString &name,
obs_source_t *source);
void AddQuickTransitionId(int id);
Expand Down

0 comments on commit 3486c0b

Please sign in to comment.