summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/World/VoxelTraversal.hpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/World/VoxelTraversal.hpp b/src/World/VoxelTraversal.hpp
index 08a53eb..f7b67be 100644
--- a/src/World/VoxelTraversal.hpp
+++ b/src/World/VoxelTraversal.hpp
@@ -17,6 +17,8 @@ struct TraversalResult {
     Position::BlockWorldOffset normal;
 };
 
+#define MC_WORLD_VOXEL_TRAVERSAL_MAX_ITERATIONS 500
+
 // Amanatides, John, and Andrew Woo. 1987.
 // "A Fast Voxel Traversal Algorithm for Ray Tracing."
 // https://doi.org/10.2312/EGTP.19871000.
@@ -52,7 +54,11 @@ TraversalResult traverse(Ray ray, P&& predicate, Real max_distance = 0) {
     // This just means we add the direction of the ray at the axis we have progressed along.
     Position::WorldOffset approach = {};
 
+    UInt iterations = 0;
     while (!predicate(block_pos)) {
+        if (iterations++ > MC_WORLD_VOXEL_TRAVERSAL_MAX_ITERATIONS)
+            return {};
+
         if (max_distance > 0 && approach.magnitude() > max_distance)
             return {};