diff --git a/src/platform/StdSchedulerWin32.cpp b/src/platform/StdSchedulerWin32.cpp index 088801739..b130c4756 100644 --- a/src/platform/StdSchedulerWin32.cpp +++ b/src/platform/StdSchedulerWin32.cpp @@ -84,14 +84,17 @@ bool StdScheduler::DoScheduleProcs(int iTimeout) } // Execute all processes with timeout + // Iterate over the index because procedures may be added or removed during execution + // (If they are removed, we skip one execution, which doesn't really matter in practice) auto tNow = C4TimeMilliseconds::Now(); - for (auto proc = procs.begin(); proc != procs.end(); ++proc) + for (size_t i_proc = 0u; i_proc < procs.size(); ++i_proc) { - auto tProcTick = (*proc)->GetNextTick(tNow); + StdSchedulerProc *proc = procs[i_proc]; + auto tProcTick = proc->GetNextTick(tNow); if (tProcTick <= tNow) - if (!(*proc)->Execute(0)) + if (!proc->Execute(0)) { - OnError(*proc); + OnError(proc); fSuccess = false; } }