Hi,
After upgrading our project to 4.6 I’ve been getting a crash in UMaterialInstance::AddReferencedObjects. Certain ULandscapeMaterialInstanceConstant objects have bHasStaticPermutationResource set to true, but StaticPermutationMaterialResources has NULL objects in it (which according to the comments in the code is never supposed to happen).
As far as I can tell the reason this is possible is because bHasStaticPermutationResource can be serialized in as true during object creation (streaming in a piece of landscape), but before UMaterialInstance::PostLoad is called (which initializes StaticPermutationMaterialResources) the garbage collector running on another thread can call UMaterialInstance::AddReferencedObjects.
I’ve fixed this locally by just checking CurrentResource is not NULL before AddReferencedObjects is called on it, but I also wonder if bHasStaticPermutationResource should be serialized, probably not. It should be false until the appropriate code determines if it should be true or not. Even so there are no protections in the code to syncronize the GC thread with the setting of bHasStaticPermutationResource to true and initializing StaticPermutationMaterialResources (the render thread that uses StaticPermutationMaterialResources does have such protections).
Cheers,
Ryan.