Browse Source

Fix possibility of degenerate OcclusionBuffer triangle edges causing a floating point division by zero. Thanks to nemerle for noticing this.

Lasse Öörni 11 years ago
parent
commit
edf9f03366
1 changed files with 2 additions and 1 deletions
  1. 2 1
      Source/Engine/Graphics/OcclusionBuffer.cpp

+ 2 - 1
Source/Engine/Graphics/OcclusionBuffer.cpp

@@ -734,7 +734,8 @@ struct Edge
     /// Construct from gradients and top & bottom vertices.
     Edge(const Gradients& gradients, const Vector3& top, const Vector3& bottom, int topY)
     {
-        float slope = (bottom.x_ - top.x_) / (bottom.y_ - top.y_);
+        float height = (bottom.y_ - top.y_);
+        float slope = (height != 0.0f) ? (bottom.x_ - top.x_) / height : 0.0f;
         float yPreStep = (float)(topY + 1) - top.y_;
         float xPreStep = slope * yPreStep;