Reentrant call to FBodyInstance::InitBody()

FBodyInstance::InitBody() was modified in v.4.11 so that the Bodies and Transforms arrays are statically allocated (rather than stack-allocated - presumably to avoid unnecessary memory allocations ), and checks were added to catch reentrant calls to this function. Unfortunately, it seems at least one reentrant case slipped through. I’m failing the check check(Bodies.Num() == 0) with the following callstack:

UE4Editor-Engine-Win64-Debug.dll!FBodyInstance::InitBody(UBodySetup * Setup, const FTransform & Transform, UPrimitiveComponent * PrimComp, FPhysScene * InRBScene, physx::PxAggregate * InAggregate) Line 2286 C++
UE4Editor-Engine-Win64-Debug.dll!UPrimitiveComponent::UnWeldFromParent() Line 821 C++
UE4Editor-Engine-Win64-Debug.dll!UPrimitiveComponent::WeldToImplementation(USceneComponent * InParent, FName ParentSocketName, bool bWeldSimulatedChild) Line 737 C++
UE4Editor-Engine-Win64-Debug.dll!FInitBodiesHelper<0>::CreateShapesAndActors_PhysX(TArray<physx::PxActor *,FDefaultAllocator> & PSyncActors, TArray<physx::PxActor *,FDefaultAllocator> & PAsyncActors, TArray<physx::PxActor *,FDefaultAllocator> & PDynamicActors, const bool bCanDefer, bool & bDynamicsUseAsyncScene) Line 1577 C++
UE4Editor-Engine-Win64-Debug.dll!FInitBodiesHelper<0>::InitBodies_PhysX() Line 1778 C++
UE4Editor-Engine-Win64-Debug.dll!FInitBodiesHelper<0>::InitBodies() Line 1390 C++
UE4Editor-Engine-Win64-Debug.dll!FBodyInstance::InitBody(UBodySetup * Setup, const FTransform & Transform, UPrimitiveComponent * PrimComp, FPhysScene * InRBScene, physx::PxAggregate * InAggregate) Line 2295 C++
UE4Editor-Engine-Win64-Debug.dll!UPrimitiveComponent::CreatePhysicsState() Line 576 C++
UE4Editor-Engine-Win64-Debug.dll!UActorComponent::ExecuteRegisterEvents() Line 1108 C++
UE4Editor-Engine-Win64-Debug.dll!UActorComponent::RegisterComponentWithWorld(UWorld * InWorld) Line 871 C++
UE4Editor-Engine-Win64-Debug.dll!AActor::IncrementalRegisterComponents(int NumComponentsToRegister) Line 3828 C++
UE4Editor-Engine-Win64-Debug.dll!ULevel::IncrementalUpdateComponents(int NumComponentsToUpdate, bool bRerunConstructionScripts) Line 806 C++
UE4Editor-Engine-Win64-Debug.dll!ULevel::UpdateLevelComponents(bool bRerunConstructionScripts) Line 739 C++
UE4Editor-Engine-Win64-Debug.dll!UWorld::UpdateWorldComponents(bool bRerunConstructionScripts, bool bCurrentLevelOnly) Line 1350 C++
UE4Editor-Engine-Win64-Debug.dll!UWorld::InitializeActorsForPlay(const FURL & InURL, bool bResetTime) Line 3079 C++
UE4Editor-Engine-Win64-Debug.dll!UGameInstance::StartPIEGameInstance(ULocalPlayer * LocalPlayer, bool bInSimulateInEditor, bool bAnyBlueprintErrors, bool bStartInSpectatorMode) Line 259 C++
UE4Editor-UnrealEd-Win64-Debug.dll!UEditorEngine::CreatePIEGameInstance(int PIEInstance, bool bInSimulateInEditor, bool bAnyBlueprintErrors, bool bStartInSpectatorMode, bool bRunAsDedicated, float PIEStartTime) Line 3077 C++
UE4Editor-UnrealEd-Win64-Debug.dll!UEditorEngine::PlayInEditor(UWorld * InWorld, bool bInSimulateInEditor) Line 2324 C++
UE4Editor-UnrealEd-Win64-Debug.dll!UEditorEngine::StartQueuedPlayMapRequest() Line 1100 C++
UE4Editor-UnrealEd-Win64-Debug.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1251 C++
UE4Editor-UnrealEd-Win64-Debug.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 370 C++
UE4Editor-Win64-Debug.exe!FEngineLoop::Tick() Line 2654 C++
UE4Editor-Win64-Debug.exe!EngineTick() Line 52 C++
UE4Editor-Win64-Debug.exe!GuardedMain(const wchar_t * CmdLine, HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, int nCmdShow) Line 145 C++
UE4Editor-Win64-Debug.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 189 C++
The problem is that InitBodies() can indirectly call UnWeldFromParent(), which may try to call InitiBody() reentrantly for NewRootBI.

For now, I’ve worked around this by removing the static designation from the Bodies and Transforms arrays, but it’d be great to have an official solution. Thanks!

–Tim

Hello tim.condon,

Thank you for this report. Would it be possible for you to provide a sample project that reproduces this issue? There haven’t been any reported of a crash similar to this since 4.8 so it would be helpful to have a reproduction case.

We haven’t heard from you in a while, tim.condon. Are you still experiencing these issues? If so, could you provide a reproduction project for this crash? In the meantime, I’ll be marking this issue as resolved for tracking purposes. Whenever you’re available, please leave a comment and the post will reopen.