fix(terrain): reject NaN rays in raycastTerrain

Without this, the AABB tests divide by ray.direction components and
NaN propagates through tmin/tmax into the triangle intersection,
returning undefined behavior at the hit position.
This commit is contained in:
Kelsi 2026-05-06 07:58:56 -07:00
parent 493cb68ddc
commit 0f15d0f3a0

View file

@ -129,6 +129,13 @@ void TerrainEditor::setVertexHeight(int chunkIdx, int vertIdx, float height) {
bool TerrainEditor::raycastTerrain(const rendering::Ray& ray, glm::vec3& hitPos) const {
if (!terrain_) return false;
// Reject NaN ray. The AABB test divides by ray.direction[i], so NaN
// would propagate through tmin/tmax and the result would be undefined.
if (!std::isfinite(ray.origin.x) || !std::isfinite(ray.origin.y) ||
!std::isfinite(ray.origin.z) || !std::isfinite(ray.direction.x) ||
!std::isfinite(ray.direction.y) || !std::isfinite(ray.direction.z)) {
return false;
}
float bestT = 1e30f;
bool hit = false;