Semi-Random Access Violation in BodyInstance.cpp


I’m currently working on a primarily C++ project in Unreal 4.7.6 that will be built for Android use. Somewhat randomly, either in editor on on the android device, I can receive access violation crashes caused by the GetSimplePhysicalMaterial() function in BodyInstance.cpp, specifically on line 2701: Material->GetPhysicalMaterial();

From the look of the code inspector when the exception is thrown, the material returned by MeshComp->GetMaterial(0); above the triggering line is corrupted in some way (Most pointers are 0xdddddddddddddddd and values are set to their minimum possible value).

This always tends to happen during a SetMaterial, although not always, despite the fact that the same material had been used fine for many previous meshes and (from the inspector’s point of view) appears fine outside of SetMaterial. Sometimes I can run the game to completion, while other times it will crash on the main menu. There doesn’t seem to be a direct way to reproduce it, although it tends to happen to a class that is regularly spawned. My MaterialInstance and StaticMesh pointers are kept static in the factory class and are not modified by anything and appear valid during the exception break.

In addition, this tends to be more prone after a hot rebuild (in the editors case - there is no correlation I can find in the Android build).

It there a particular way to handle materials that I might be missing. I don’t actually need or have any use for physical materials, so if there is a way to flat out avoid that check that would be great. I know this is a haphazard report, but if I discover more on either how to reproduce or what I was doing wrong I will update this question as appropriate.


Hi -

Can you check your code and insure that the Material that you are setting is not being Garbage collected? Make sure that what you are setting it in the class as a Uproperty and that the Material being set is valid.

Thank You

Eric Ketchum

Adding UProperty and removing static appears to have made it work. I’m going to blame Visual Studio’s inspector for appearing to show valid data when I moved up the call stack. Thanks!

Just another question regarding UProperty. Does adding UProperty add or otherwise handle the variable with regards to the garbage collector? I didn’t add UProperty as I didn’t have the need to access those variables from within the editor (I assumed UProperty handled the editor bindings).

Thanks again!

Hey -

Along with exposing the variable to the editor so it can recognize it, using UPROPERTY does control garbage collection for the variable to make sure that all housekeeping tasks related to it are completed before the object is deleted/removed


Excellent, thank you for the help!