From f73c841bfe8c04eb77f06f6c8c9bd27bf2c8e044 Mon Sep 17 00:00:00 2001 From: MysterD Date: Mon, 14 Feb 2022 18:28:01 -0800 Subject: [PATCH] Fixed crash in init_shadow() --- src/engine/math_util.c | 2 +- src/game/shadow.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/engine/math_util.c b/src/engine/math_util.c index c398243b3..19b1e79a4 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -736,7 +736,7 @@ static u16 atan2_lookup(f32 y, f32 x) { ret = gArctanTable[0]; } else { s32 index = (s32)(y / x * 1024 + 0.5f); - if (index >= 0x401) { index = 0; } + if (index >= 0x401 || index < 0) { index = 0; } ret = gArctanTable[index]; } return ret; diff --git a/src/game/shadow.c b/src/game/shadow.c index 5bbb4e9cb..c6315c633 100644 --- a/src/game/shadow.c +++ b/src/game/shadow.c @@ -234,6 +234,9 @@ s8 init_shadow(struct Shadow *s, f32 xPos, f32 yPos, f32 zPos, s16 shadowScale, s->floorNormalY = floorGeometry->normalY; s->floorNormalZ = floorGeometry->normalZ; s->floorOriginOffset = floorGeometry->originOffset; + } else { + // You can't draw a shadow with no floor under you. + return 1; } if (overwriteSolidity) {