Crash in GetPhysXScene when cleaning up DestructibleComponent

We are currently on 4.6 preview. We are getting the crash below when using ServerTravel to restart a level. Oddly the crash does not occur when using ClientTravel. I don’t know what affect that has on how object cleanup is handled.

 	KernelBase.dll!000007fefd0a3ca2()	Unknown
>	UE4Editor-Core-Win64-Debug.dll!StaticFailDebug(const wchar_t * Error, const char * File, int Line, const wchar_t * Description, bool bIsEnsure) Line 190	C++
 	UE4Editor-Core-Win64-Debug.dll!FDebug::AssertFailed(const char * Expr, const char * File, int Line, const wchar_t * Format, ...) Line 224	C++
 	UE4Editor-Engine-Win64-Debug.dll!FPhysScene::GetPhysXScene(unsigned int SceneType) Line 1029	C++
 	UE4Editor-Engine-Win64-Debug.dll!UDestructibleComponent::DestroyPhysicsState() Line 362	C++
 	UE4Editor-Engine-Win64-Debug.dll!UActorComponent::ExecuteUnregisterEvents() Line 832	C++
 	UE4Editor-Engine-Win64-Debug.dll!UActorComponent::UnregisterComponent() Line 680	C++
 	UE4Editor-Engine-Win64-Debug.dll!AActor::UnregisterAllComponents() Line 3030	C++
 	UE4Editor-Engine-Win64-Debug.dll!ULevel::ClearLevelComponents() Line 658	C++
 	UE4Editor-Engine-Win64-Debug.dll!UWorld::ClearWorldComponents() Line 1133	C++
 	UE4Editor-Engine-Win64-Debug.dll!UWorld::CleanupWorld(bool bSessionEnded, bool bCleanupResources, UWorld * NewWorld) Line 3042	C++
 	UE4Editor-Engine-Win64-Debug.dll!FSeamlessTravelHandler::Tick() Line 4561	C++

To create this problem on our end we simply have a DestructibleMesh which we drag into that map which creates a DestructibleActor. Launch a standalone game. Then finally use ServerTravel with the ?restart option.

The crash occurs at the SceneType < NumPhysScenes check. The problem is that SceneType is equal to NumPhysScenes. In UDestructibleComponent::DestroyPhysicsState the UseAsyncScene check returns True so GetPhysXScene is called with PST_Async. I don’t think this should happen as bEnableAsyncScene is False. So I dug into UseAsyncScene. When UseAsyncScene is called for the DestructibleComponent. The OwnerComponent.IsValid check fails even though OwnerComponent appears to valid when debugging. The result is that UseAsyncScene returns True since the default value of bHasAsyncScene and bUseAsyncScene are True even though there should be no AsyncScene.

The best solution I could figure out was to have bHasAsyncScene default to False in UseAsyncScene. This fixes the crash but I’m not familiar with the physics code to be sure this is a safe change. Can you think of any problems this could cause?

Same problem occurs in the

UInstancedStaticMeshComponent::SetupNewInstanceData

BodyInstance.OwnerComponent is invalid for some reason and the

bool FBodyInstance::UseAsyncScene() const

returns true. Totally agree with Overkitty, we need this fix in the official build;)

Hi all,
Thanks for looking into this. I’ve submitted what I believe is a fix here: https://github.com/EpicGames/UnrealEngine/commit/c32afe23b2ca7d14659856456b3fb631cd4b3409