Skip to content

Commit 2452cb0

Browse files
committed
Fix TrackViewer crash on big zoom value
The method Matrix.CreatePerspectiveFieldOfView throw an ArgumentException when value passed for the nearPlaneDistance parameter is less or equals to zero. With a really big zoom value, width become 0.0 and result of pass zero for value of nearPlaneDistance parameter, that cause unhandled exception.
1 parent 8f19fcc commit 2452cb0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Source/Contrib/TrackViewer/Drawing/DrawTerrain.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,14 @@ void UpdateCamera(DrawArea drawArea)
486486
float camHeight = width / device.Viewport.AspectRatio / 2;
487487
Vector3 cameraPosition = cameraTarget;
488488
cameraPosition.Y = -camHeight;
489+
float nearPlaneDistance = camHeight / 2;
490+
if (nearPlaneDistance <= 0)
491+
{
492+
// distance is too close for CreatePerspectiveFieldOfView
493+
return;
494+
}
489495
basicEffect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, new Vector3(0, 0, 1));
490-
basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, device.Viewport.AspectRatio, camHeight / 2, camHeight * 2);
496+
basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, device.Viewport.AspectRatio, nearPlaneDistance, camHeight * 2);
491497

492498
}
493499
#endregion

0 commit comments

Comments
 (0)