mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-06-14 12:51:43 -05:00
Fix crash when deleting macro with wait action
Note that this might still not be completely race free but should improve the situation a lot.
This commit is contained in:
parent
1474509cb9
commit
06ea7bf1d9
|
|
@ -424,8 +424,9 @@ void SwitcherData::Stop()
|
|||
{
|
||||
if (th && th->isRunning()) {
|
||||
stop = true;
|
||||
transitionCv.notify_one();
|
||||
cv.notify_one();
|
||||
abortMacroWait = true;
|
||||
macroWaitCv.notify_one();
|
||||
th->wait();
|
||||
delete th;
|
||||
th = nullptr;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ struct SwitcherData {
|
|||
std::mutex m;
|
||||
bool transitionActive = false;
|
||||
bool waitForTransition = false;
|
||||
std::condition_variable transitionCv;
|
||||
bool stop = false;
|
||||
bool verbose = false;
|
||||
bool disableHints = false;
|
||||
|
|
@ -92,6 +91,8 @@ struct SwitcherData {
|
|||
std::chrono::high_resolution_clock::time_point lastMatchTime;
|
||||
|
||||
std::deque<Macro> macros;
|
||||
std::condition_variable macroWaitCv;
|
||||
std::atomic_bool abortMacroWait = {false};
|
||||
bool macroSceneSwitched = false;
|
||||
bool replayBufferSaved = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,8 @@ void AdvSceneSwitcher::RemoveMacroAction(int idx)
|
|||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
macro->Actions().erase(macro->Actions().begin() + idx);
|
||||
switcher->abortMacroWait = true;
|
||||
switcher->macroWaitCv.notify_one();
|
||||
macro->UpdateActionIndices();
|
||||
|
||||
// All entry pointers in existing edit widgets after the new entry will
|
||||
|
|
|
|||
|
|
@ -38,10 +38,12 @@ bool MacroActionWait::PerformAction()
|
|||
sleep_duration);
|
||||
|
||||
std::unique_lock<std::mutex> lock(switcher->m);
|
||||
auto r = switcher->cv.wait_for(
|
||||
switcher->abortMacroWait = false;
|
||||
switcher->macroWaitCv.wait_for(
|
||||
lock,
|
||||
std::chrono::milliseconds((long long)(sleep_duration * 1000)));
|
||||
return r == std::cv_status::timeout;
|
||||
std::chrono::milliseconds((long long)(sleep_duration * 1000)),
|
||||
[] { return switcher->abortMacroWait.load(); });
|
||||
return !switcher->abortMacroWait;
|
||||
}
|
||||
|
||||
bool MacroActionWait::Save(obs_data_t *obj)
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@ void AdvSceneSwitcher::on_macroRemove_clicked()
|
|||
QString name;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->abortMacroWait = true;
|
||||
switcher->macroWaitCv.notify_one();
|
||||
int idx = ui->macros->currentRow();
|
||||
QString::fromStdString(switcher->macros[idx].Name());
|
||||
switcher->macros.erase(switcher->macros.begin() + idx);
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ bool Macro::PerformAction()
|
|||
{
|
||||
bool ret = true;
|
||||
for (auto &a : _actions) {
|
||||
ret = ret && a->PerformAction();
|
||||
a->LogAction();
|
||||
ret = ret && a->PerformAction();
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user