Skip to content

Commit

Permalink
UpdateHandle - Fix error on call after completion
Browse files Browse the repository at this point in the history
If a CallAfterHandle's completion disposed another CallAfterHandle or the UpdateHandle itself within the stack the iteration would error/fail.

IsDisposed is now checked on each iteration. Improvements to the fix are described in #148
  • Loading branch information
mbaker3 committed Sep 23, 2023
1 parent 6050a8b commit 29d1783
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion DelayedExecution/UpdateHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ private void UpdateSource_OnUpdate()
m_UpdateIterator.AddRange(m_CallAfterHandles.Values);
foreach (CallAfterHandle callAfterHandle in m_UpdateIterator)
{
//TODO: #148 - Move to a two phase Update then Dispatch pass to avoid branching in the loops.
// If the previous call handle updating caused the UpdateHandle to be disposed then stop updating
// call handles. They'll all be disposed.
if (IsDisposed)
{
break;
}

// If one of the previous call handles caused this call handle to be disposed then skip it.
if (callAfterHandle.IsDisposed)
{
continue;
}

callAfterHandle.Update();
}
m_UpdateIterator.Clear();
Expand Down Expand Up @@ -217,4 +231,4 @@ private void CallAfterHandle_OnDisposing(CallAfterHandle callAfterHandle)
ValidateUpdateSourceHook();
}
}
}
}

0 comments on commit 29d1783

Please sign in to comment.