From aa53ff2b29e78674ff8cf8f58838bba1b13bfd3a Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Wed, 8 Jun 2016 18:36:22 +0200 Subject: [PATCH] Fix possible NREs in RenderAsync in VoxelRenderer.cs --- OpenRA.Game/Graphics/VoxelRenderer.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Graphics/VoxelRenderer.cs b/OpenRA.Game/Graphics/VoxelRenderer.cs index 868a65fbaf..44c6c89a12 100644 --- a/OpenRA.Game/Graphics/VoxelRenderer.cs +++ b/OpenRA.Game/Graphics/VoxelRenderer.cs @@ -94,6 +94,8 @@ namespace OpenRA.Graphics var invShadowTransform = Util.MatrixInverse(shadowTransform); var cameraTransform = Util.MakeFloatMatrix(camera.AsMatrix()); var invCameraTransform = Util.MatrixInverse(cameraTransform); + if (invCameraTransform == null) + throw new InvalidOperationException("Failed to invert the cameraTransform matrix during RenderAsync."); // Sprite rectangle var tl = new float2(float.MaxValue, float.MaxValue); @@ -199,9 +201,12 @@ namespace OpenRA.Graphics { var rd = v.Voxel.RenderData(i); var t = v.Voxel.TransformationMatrix(i, frame); + var it = Util.MatrixInverse(t); + if (it == null) + throw new InvalidOperationException("Failed to invert the transformed matrix of frame {0} during RenderAsync.".F(i)); // Transform light vector from shadow -> world -> limb coords - var lightDirection = ExtractRotationVector(Util.MatrixMultiply(Util.MatrixInverse(t), lightTransform)); + var lightDirection = ExtractRotationVector(Util.MatrixMultiply(it, lightTransform)); Render(rd, Util.MatrixMultiply(transform, t), lightDirection, lightAmbientColor, lightDiffuseColor, color.TextureMidIndex, normals.TextureMidIndex);