mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 01:23:52 +00:00
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:
parent
493cb68ddc
commit
0f15d0f3a0
1 changed files with 7 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue