Good day everyone.
Kieran is currently on vacation, so I had a look at the crashes, as we still got Sentry reports for it.
Ultimately, the fix [mention removed] linked probably fixed the issue partially, but I think it also needs a small additional change.
As already reported by Kieran, the callstack hits `FMovieSceneEntitySystemRunner::GameThread_PostEvaluationPhase (MovieSceneEntitySystemRunner.cpp:1366)`
That’s this code here:
for (const FSimpleDelegate& OnFlushed : TmpOnFlushedDelegates)
{
OnFlushed.Execute();
}
The `TmpOnFlushedDelegates` is filled by swapping `OnFlushedDelegates` into it, at the top of the function.
Now, `OnFlushedDelegates` is filled in `::GameThread_UpdateSequenceInstances` like this:
// Always forward the OnFlushed delegate to be called at the end of the frame, even if the instance is no longer valid
if (Update.OnFlushed.IsBound())
{
OnFlushedDelegates.Add(MoveTemp(Update.OnFlushed));
// If we have any on-flushed delegates then we have to do a full Post-Eval phase
AccumulatedUpdateFlags |= ESequenceInstanceUpdateFlags::NeedsPostEvaluation;
}
There are two things to point out.
- `if (Update.OnFlushed.IsBound())` makes sure that the delegate `IsSafeToExecute`, which means at this point it’s all valid.
- The comment above the if saying `even if the instance is no longer valid`
To me this means that we are expecting that the instance could become invalid from here until we actually call the `Execute()`.
In other words, `OnFlushed.Execute();` should become `OnFlushed.ExecuteIfBound();`.
That should™️fully resolve the issue. I think, it can happen that between `::GameThread_UpdateSequenceInstances` and `::GameThread_PostEvaluationPhase`, which are called within `::FlushNext`, the instance can indeed die, and there is nothing that checks anymore if the delegate `IsSafeToExecute`.
I haven’t submitted that change internally yet, but probably will to at least try and mitigate the crash.
Cheers.
[Attachment Removed]