UMaterialInstanceDynamic::Create( causes crash if a NULL MaterialInterface is passed in

Dear Friends at Epic,

Can you check out UMaterialInstanceDynamic::Create( and make sure it handles being passed in a UMaterialInterface* that is NULL in the correct manner?

I sometimes get a crash on the rendering thread when passing in a NULL material (it was not intentional of course, but when it crashes, it doesn’t explain what the problem is at all, in the log)

This is just one more step to be make Engine able to handle CPP user-error without crashing

Thanks!

#This

//Create Highlighted and Active Mat Insts
if(!VISVALID(ItemHighlightedMatInst))
{
	ItemHighlightedMatInst 	= UMaterialInstanceDynamic::Create(SolusInventoryMaterial_HighlightedItemMaterial,GetWorld());
}


if(!VISVALID(ItemActiveMatInst))
{
	ItemActiveMatInst 		= UMaterialInstanceDynamic::Create(SolusInventoryMaterial_ActiveItemMaterial,GetWorld());
}

#had to become this

//Create Highlighted and Active Mat Insts
if(SolusInventoryMaterial_HighlightedItemMaterial)
{
	if(!VISVALID(ItemHighlightedMatInst))
	{
		ItemHighlightedMatInst 	= USolusCore::UMaterialInstanceDynamic::Create(SolusInventoryMaterial_HighlightedItemMaterial,GetWorld());
	}
}
if(SolusInventoryMaterial_ActiveItemMaterial)
{
	if(!VISVALID(ItemActiveMatInst))
	{
		ItemActiveMatInst 		= UMaterialInstanceDynamic::Create(SolusInventoryMaterial_ActiveItemMaterial,GetWorld());
	}
}

#Where to Start Looking

The most relevant code is right here (abbreviated for legal reasons)

MaterialInstance.cpp

void UMaterialInstance::SetParentInternal(UMaterialInterface* NewParent)

#My Best Guess at the Issue

In the case when the NewParent is NULL, the InitResources() is still running.

	InitResources();

The overall process should probably exit more cleanly, maybe even in the MaterialInstanceDynamic::Create(, and never running SetParentInternal.

#Summary

UMaterialInstanceDynamic::Create( is crashing when the material to make the materian instance dynamic from was NULL

I have experienced reproduceable crashes related to passing in NULL for ::Create( so please check this out

You may have to run the code several times to get the crash, for me it is between 1 and 3 runs of the code during runtime before the crash occurs.

Rama