Problem:
The engine silently crashes on level load or when changing the viewport to an orthographic view.
Cause:
The problem is that the orthographic viewport cameras are not properly initialized sometimes. This causes
FEditorCommonDrawHelper::DrawGridSection to overflow when because:
const float Zoom = (1.0f / View->ViewMatrices.ProjMatrix.M[0][0]) * 2.0f / SizeX;
gets set to an extremely large value which causes IncScale to overflow to zero:
float IncValue = FMath::LogX(Exponent, Dist / (float)(SizeX / Tweak));
int32 IncScale = 1;
for(float x = 0; x < IncValue; ++x)
{
IncScale *= Exponent;
}
Which causes an unhandled divide by zero exception:
const int32 FirstLineClamped = FMath::Max<int32>(FirstLine - 1,-HALF_WORLD_MAX/ViewportGridY) / IncScale;
const int32 LastLineClamped = FMath::Min<int32>(LastLine + 1, +HALF_WORLD_MAX/ViewportGridY) / IncScale;
Workarounds:
- Open an empty level
- Disable grid drawing
- Open the problematic level, select an object in your world, hit F to cause the viewport to center around the object
- Renable grid drawing
Solution
Not sure the exact context of what causes the ortho views to be uninitialized. We have several very large levels in a single map that are streamed in. Didn’t have time to do in-depth call stack trace but I’m sure someone from Epic who knows this part of the code can fix it quickly.