[4.11] PhysX component-related crash

Hi there,

I’ve been tracking a painful crash for two days, since Preview 7 came out. Basically our game always crash at launch on the 4.11 branch but we have no idea what causes it. Things than can cause it include :

  • UStaticMeshComponent::SetStaticMesh
  • UStaticMeshComponent::SetMaterial
  • UPrimitiveComponent::DestroyPhysicsState (when exiting)

We’re probably doing something wrong (the game creates, moves, attaches a lot of components) but the issue is new from Preview 7, and it feels like the crash is too low level. The UE4 state looks fine - we’re not calling these on NULL or 0xcdcdcdcd, but on valid, existing and sane objects. We’ve checked that. We’re also pretty sure we didn’t change anything related to this part of our code base for months.

Here are typical call stacks for this issue. When using SetMaterial

PhysX3CommonPROFILE_x64.dll!physx::shdfnd::atomicDecrement(volatile int * val) Line 45 C++
PhysX3PROFILE_x64.dll!physx::NpShape::setMaterials(physx::PxMaterial * const * materials, unsigned short materialCount) Line 498 C++
UE4Editor-Engine.dll!FBodyInstance::ApplyMaterialToShape_AssumesLocked(physx::PxShape * PShape, physx::PxMaterial * PSimpleMat, const TArray<UPhysicalMaterial *,FDefaultAllocator> & ComplexPhysMats, const bool bSharedShape) Line 4559 C++
UE4Editor-Engine.dll!ExecuteOnPxShapeWrite<void (physx::PxShape *) >(FBodyInstance * BodyInstance, physx::PxShape * PShape, FBodyInstance::ApplyMaterialToInstanceShapes_AssumesLocked::__l4::void (physx::PxShape *) Func) Line 700 C++
UE4Editor-Engine.dll!FBodyInstance::ApplyMaterialToInstanceShapes_AssumesLocked(physx::PxMaterial * PSimpleMat, TArray<UPhysicalMaterial *,FDefaultAllocator> & ComplexPhysMats) Line 4570 C++
UE4Editor-Engine.dll!FBodyInstance::ExecuteOnPhysicsReadWrite(TFunctionRef<void __cdecl(void)> Func) Line 2984 C++
UE4Editor-Engine.dll!FBodyInstance::UpdatePhysicalMaterials() Line 421 C++
UE4Editor-Engine.dll!UMeshComponent::SetMaterial(int ElementIndex, UMaterialInterface * Material) Line 72 C++

When exiting the game

PhysX3CommonPROFILE_x64.dll!physx::shdfnd::atomicDecrement(volatile int * val) Line 45 C++
PhysX3PROFILE_x64.dll!physx::NpShape::~NpShape() Line 53 C++
[External Code]
PhysX3PROFILE_x64.dll!physx::NpFactory::releaseShapeToPool(physx::NpShape & shape) Line 874 C++
PhysX3PROFILE_x64.dll!physx::NpDestroy(physx::Scb::Base & base) Line 1249 C++
PhysX3PROFILE_x64.dll!physx::Scb::Scene::removephysx::Scb::Body,1(physx::Scb::Body & v, physx::Scb::ObjectTracker & tracker, bool wakeOnLostTouch) Line 411 C++
PhysX3PROFILE_x64.dll!physx::Scb::Scene::removeRigidBody(physx::Scb::Body & body, bool wakeOnLostTouch, bool noSim) Line 601 C++
PhysX3PROFILE_x64.dll!physx::NpRigidDynamic::release() Line 66 C++
UE4Editor-Engine.dll!TermBodyHelper(short & SceneIndex, physx::PxRigidActor * & PRigidActor, FBodyInstance * BodyInstance) Line 1847 C++
UE4Editor-Engine.dll!FBodyInstance::TermBody() Line 1900 C++
UE4Editor-Engine.dll!UPrimitiveComponent::DestroyPhysicsState() Line 574 C++
UE4Editor-Engine.dll!UActorComponent::ExecuteUnregisterEvents() Line 1120 C++
UE4Editor-Engine.dll!UActorComponent::UnregisterComponent() Line 945 C++
UE4Editor-Engine.dll!AActor::UnregisterAllComponents() Line 3737 C++
UE4Editor-Engine.dll!ULevel::ClearLevelComponents() Line 659 C++
UE4Editor-Engine.dll!UWorld::ClearWorldComponents() Line 1268 C++
UE4Editor-Engine.dll!UWorld::CleanupWorld(bool bSessionEnded, bool bCleanupResources, UWorld * NewWorld) Line 3225 C++
UE4Editor-UnrealEd.dll!UEditorEngine::TeardownPlaySession(FWorldContext & PieWorldContext) Line 653 C++
UE4Editor-UnrealEd.dll!UEditorEngine::EndPlayMap() Line 255 C++

Reproduces on

  • 4.11 Preview 7 both on source or binary
  • 4.11 head (58e0a2044ee5952a7dcd895ba53e889d6903d5dc as of now)

Doesn’t reproduce on

  • 4.11 Preview 6 both on source or binary
  • promoted head (bf634d600724c835dfac4c0b3f807480f072d292 as of now)

Sorry about the lack of details. We’ve been unable to track down what causes the crash.

Thanks !

I have the same problem with 4.11 HEAD on linux.

Hey -

Can you provide the log files from the crash as well. If possible, could you send a copy of the failing project? This can be done by either zipping the project and posting here or uploading it to DropBox or google drive and send me a PM on the forums with a download link for privacy.

So far I have tested SetStaticMesh and SetMaterial, both of which I was able to open the project and PIE after adding the code to a custom class. In case DestroyPhysicsState is part of the issue I would like to make sure my setup matches what you’re doing as closely as possible.


Hi ,

I’m sending you the project files.

Hey -

I got the project you sent and after debugging in Visual Studio it appears that the crash consistently occurs in FlareSpacecraftComponent.cpp at line 165 (FLOGV(“LOD %d APPLY EffectMaterial %s”, LODIndex,*EffectMaterial->GetName());). Further, I realized that the crash occurs when EffectMaterial is equal to “MaterialInstanceDynamic”_34. I say this because it appears to run through this function multiple times with EffectMaterial having a different value each time (first _30, then _32, then crash at _34). The issue seems to be with whatever this value represents, however I can’t dig further as I am not sure where this value is coming from.

This is consistent with what we’re seeing.

The behavior you described is expected. This function creates two material instances for each mesh, and applies it to every LOD section. What we’re trying to understand is why SetMaterial() crashes.

Trouble is, the crash occurs inside PhysX, and we have no idea what is supposed to happen inside that - I don’t believe the source is available for that particular part of UE4. You should have roughly the same call stack as quoted above (physx::shdfnd::atomicDecrement etc).

Hey -

The callstack I received did not mention physx::shdfnd::atomicDecrement, however after testing again on Linux I did receive the same error. This issue may be specific to Linux and I have entered a bug report (UE-28399) for further investigation.


Thanks !

It’s strange because I’m having this issue in a very reproducible fashion, both in source and binary releases of 4.11 P7 on Windows, and Linux source. We tested those three versions and we’re getting very consistent results. On Windows, in debug builds, we’re always getting the crash inside PhysX3PROFILE_x64.dll.

Any news ?

The crash that was occurring when SetMaterial was called has been addressed internally and should be fixed in the final 4.11 release.

Thank you so much !