From 63174b401dd2bf1e43ef1db56868347921b8596b Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Wed, 1 Jun 2022 19:48:48 -0400 Subject: [PATCH] [game] prevent NaNs when there's a zero area triangle in edgegrab (#1404) --- game/mips2c/functions/collide_edge_grab.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/game/mips2c/functions/collide_edge_grab.cpp b/game/mips2c/functions/collide_edge_grab.cpp index e5e6a7b468..82969343e2 100644 --- a/game/mips2c/functions/collide_edge_grab.cpp +++ b/game/mips2c/functions/collide_edge_grab.cpp @@ -104,6 +104,12 @@ u64 execute(void* ctxt) { c->vmadd_bc(DEST::w, BC::z, vf9, vf0, vf9); // vmaddz.w vf9, vf0, vf9 // nop // sll r0, r0, 0 c->vrsqrt(vf0, BC::w, vf9, BC::w); // vrsqrt Q, vf0.w, vf9.w + if (c->vfs[vf9].f[3] == 0.f) { + // hack to prevent NaNs from getting in the collide data if we have a zero-area triangle + // this value doesn't matter - the normal is zeros anyway and the triangle will be rejected + // by every other step. + c->Q = 0.f; + } // nop // sll r0, r0, 0 c->dsll32(t5, t5, 12); // dsll32 t5, t5, 12 c->dsrl32(t5, t5, 26); // dsrl32 t5, t5, 26