4.12 infinite loop in engine source + fix

After converting our project to 4.12 and updating the code I found out when my editor is starting up, it gets stuck in an infinite loop related to cube maps. In the precompiled 4.12.2 hotfix, the loop it gets stuck on is in FinalPostProcessSettings.h, line 52.

Stepping through the code quickly reveals the cause:

for(int32 i = 0; i < ContributingCubemaps.Num(); ++i)
{
	--- some lines omitted ---

	if(Local.AmbientCubemapTintMulScaleValue.IsAlmostBlack())
	{
		ContributingCubemaps.RemoveAt(i, /*bAllowShrinking=*/ false);
		i--; // Maintain same index in the loop after loop increment since we removed an element.
	}
}

The signature of RemoveAt is: int32 Index, int32 Count, bool bAllowShrinking. So the call to RemoveAt is wrong, the ‘false’ passed to RemoveAt is being received as Count = 0 instead of bAllowShrinking. Thus, nothing is actually removed there and yet i-- is executed. The call should be this instead:

    		ContributingCubemaps.RemoveAt(i, 1, /*bAllowShrinking=*/ false);

I would fix it myself and send a pull request, but I don’t have UE4 from source on my machine currently. Could someone please fix this?

Great find Zhi! Wohoo! Saving the Engine!

I submitted PR here:

https://github.com/EpicGames/UnrealEngine/pull/2504

FYI: There is another issue very similar to this. The editor actually opens however, it does not freeze until you open an asset such as a static mesh or anything else. Also, playing from the editor does not work either. Causes the same freeze. This fix does not work in this scenario. Still trying to find where it’s hanging up.