Sequencer causing a "Fatal world leaks detected" crash

Hello,

We recently had a few occurrences of crashes caused by a “Fatal world leaks detected” error when unloading a level (in a packaged game and in editor).

I tracked down what was keeping a references to a uobject preventing the world to be GCed and it led me to the sequencer, a TStrongObjectPtr was still holding a reference to an animation blueprint. The pointer was assigned by OutCachedValue.CachedAnimInstance.Reset(Component->AnimScriptInstance); in FPreAnimatedSkeletalAnimationTraits::CachePreAnimatedValue() but FPreAnimatedSkeletalAnimationTraits::RestorePreAnimatedValue was never called even though the sequence had stopped playing.

It turns out that this issue happen in some very specific conditions. I’ve put some details in the repro steps and project, but the main factors are the following:

  • a level sequence plays an animation on a skeletal mesh’s animation blueprint
  • it also spawns an actor that plays a second sequence (through an actor sequence component in our case)

What happens is that when the main sequence stops:

  • FMovieSceneEntitySystemRunner::QueueFinalUpdate() and then FMovieSceneEntitySystemRunner::FlushOutstanding() is called
  • During the ERunnerFlushState::Import phase, in FSequenceInstance::Finish(), a call to Ledger.UnlinkEverything(Linker) adds a NeedsUnlink component to the sequence’s entities.
  • Further in the same Finish() function, a call to SpawnRegister->CleanUp() does a DestroyObjectsByPredicate() and destroys spawned actors
  • When the spawned actors gets destroyed, in our case UActorSequenceComponent::EndPlay is called and the playing sequence is stopped
  • In SequencePlayer->TearDown(), UMovieSceneEntitySystemLinker::CleanGarbage() endup being called
  • In UMovieSceneEntitySystemLinker::CleanGarbage(), a EntityManager.FreeEntities() is done on all entities with a NeedsUnlink component, thus wiping the work that was done in the Import phase
  • Later in the Instantiation phase, UMovieSceneRestorePreAnimatedStateSystem::OnRun() won’t find any entities with the NeedsUnlink component to cleanup so RestorePreAnimatedValue() won’t be called

In order to fix this issue, in UMovieSceneEntitySystemLinker::CleanGarbage() I added a check to see if an evaluation phase was already in progress before doing a FreeEntities:

[Image Removed]

In this case the ResetRunner() and the subsequence evaluation restart should take care of the cleanup if I’m not mistaken.

Let me know if it’s a know issue on your side, and if this fix seems valid to you or if there is a better way to handle this situation.

Steps to Reproduce
In the provided repro project, just open the Level, hit play in editor, and the crash should happen after 2 seconds.

The main elements to trigger the issue are the following:

  • [BP_SpawnedByLevelSequence] A blueprint with an actor sequence component set to auto run (but I’m pretty sure that starting and stopping a classic level sequence in the beginplay / endplay of the BP instead of using the component would do the same)
  • [BP_SkeletalMesh] A character BP with a skeletal mesh animated with an animation blueprint [ABP_SkeletalMesh]
  • [LevelSequence] A level sequence actor placed in the level is playing this sequence. The important bits of this sequence are:
    • It possesses BP_SkeletalMesh placed in the level and plays an animation in one of its slots
    • It spawns a BP_SpawnedByLevelSequence (that will also play its own sequence)
  • [Level] In the level blueprint the OpenLevel is called after 2 seconds to unload the world and trigger a GC

Hey There,

Thanks for raising this, this is a good catch. I’ve logged a bug that you can follow along at https://issues.unrealengine.com/issue/UE-282364 (It will take some time to show up)

In terms of whether this fix is valid, right now this seems like a good direction. As we go to fix this issue, we may find more things so you might want to check in to git after the above bug has been addressed.

One thing to reiterate as well, Actor Sequence Component is experimental and is not being actively developed at the moment. This issue isn’t necessarily related to Actor Sequence Component, but just wanted to reiterate that further use might cause more issues.

Hey Dustin,

Thanks for the quick reply and for bugtracker link, I’ll keep an eye on it.

I’ve deployed the fix yesterday and haven’t seen any occurrence of the crash or unwanted side effects since then so its going well so far.

About the actor sequence component I agree, I already raised a flag internally about its usage.

Have a great day!

Hey,

I stumbled upon similar issue in the project I am working on. I was wondering if it’s possible to repost the solution that OP claimed it fixed their issues. I assume it could have been there where the [Image Removed] tag resides.