Nullptr Crash When Loading Animation

Hi Epic,

When starting the editor or game, or starting PIE, rarely it crashes becausing of dereferencing nullptr in UAnimSequencerController::RemoveBoneTracksMissingFromSkeleton. The revelant line is the following, and GetObjectBinding() returns nullptr.

const UObject* BoundControlRigObject = Model->GetControlRig()->GetObjectBinding()->GetBoundObject();

We think the normal flow is:

  1. Unreal is loading the animation sequencer data model. (UObject::ConditionalPostLoad)
  2. As part of it, it loads the animation sequence. (calls ConditionalPostLoadSubobjects())
  3. In UAnimSequenceBase::PostLoad, it attempts to call RemoveBoneTracksMissingFromSkeleton. But at this point, GetPackage()->GetHasBeenEndLoaded() should return false, and thus it will wait for OnEndLoadPackage event to happen which will then trigger UAnimSequenceBase::OnEndLoadPackage.
  4. Back to UObject::ConditionalPostLoad, we will call UAnimationSequencerDataModel::PostLoad() which calls InitializeFKControlRig, which now sets the control rig’s object binding.
  5. After that, FAsyncLoadingThread::ProcessLoadedPackages will mark the package as HasBeenEndLoaded, and triggers OnEndLoadPackage event.
    And then the anim sequence will call RemoveBoneTracksMissingFromSkeleton.

But the reason why the crash happens is, in step 3, GetPackage()->GetHasBeenEndLoaded() returns true for some reason, causing it to call RemoveBoneTracksMissingFromSkeleton already. But the control rig’s object binding is still null, which will cause the crash. You can see this from the callstack.

It happens quite rarely and not on the same anim sequence. It seems to occur after we upgraded to UE 5.4.

As a temp workaround, we modified that function to add a few validity checks, so that if GetObjectBinding() is null, it will just exit the function.