RigVM InstructionIndex out of bounds

As described in the steps to reproduce, it would appear that switching back and forth between multiple linked anim layers that use the same ControlRig, by unlinking the active one and then linking the other (repeatedly) can can a RigVM crash where it attempts to access an invalid TArray entry (executing on a worker thread as part of the animgraph evaluation). The FirstHandleForInstruction URigVM is reset/reconstructed when the animation layers that reference the control rig is linked, modifying the shared RigVM:

URigVMRuntimeAsset::InitializeInstance -> URigVM::PrepareMemoryForExecution

[Attachment Removed]

Steps to Reproduce
Have two linked animation layers reference and use the same control rig. On the game thread switch back and forth between them, unlinking the active linked animation layer, then linking the other. Repro can be unreliable as this seems to be a threading issue. Eventually you will hit an index out of bound check in the TArray caused by:

const int32 OperandCount = FirstHandleForInstruction[ContextPublicData.InstructionIndex + 1] - FirstHandleForInstruction[ContextPublicData.InstructionIndex];

[Attachment Removed]

Hey there,

Thanks for raising this, we recently made a fix for some other crashes around some of the same issues as this. This change might address your issue, but let us know if it doesn’t.

https://github.com/EpicGames/UnrealEngine/commit/0e9cee8095f377f00c272db822f2ea7bf6b1241f

Dustin

[Attachment Removed]

Hi Dustin,

Thank you for your response!

[Attachment Removed]