From 3478db9655e11c66628da771fd3dcb76f94ff9e7 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 12 May 2023 12:31:11 -0700 Subject: [PATCH] Fix more possible crashes --- src/game/mario_actions_airborne.c | 2 +- src/game/mario_step.c | 16 +++++++++------- src/game/rumble_init.c | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index c4eef2a3..eedba759 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -96,7 +96,7 @@ s32 check_fall_damage(struct MarioState *m, u32 hardFallAction) { #pragma GCC diagnostic pop - if (m->action != ACT_TWIRLING && m->floor->type != SURFACE_BURNING) { + if (m->action != ACT_TWIRLING && m->floor && m->floor->type != SURFACE_BURNING) { if (m->vel[1] < -55.0f) { if (fallHeight > 3000.0f) { m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 16 : 24; diff --git a/src/game/mario_step.c b/src/game/mario_step.c index e00f98f7..21b559bc 100644 --- a/src/game/mario_step.c +++ b/src/game/mario_step.c @@ -120,7 +120,9 @@ u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) { m->quicksandDepth = 1.1f; } - switch (m->floor->type) { + u32 floorType = m->floor ? m->floor->type : SURFACE_DEFAULT; + + switch (floorType) { case SURFACE_SHALLOW_QUICKSAND: if ((m->quicksandDepth += sinkingSpeed) >= 10.0f) { m->quicksandDepth = 10.0f; @@ -355,11 +357,11 @@ s32 perform_ground_step(struct MarioState *m) { } for (i = 0; i < 4; i++) { - Vec3f step = { - m->floor->normal.y * (m->vel[0] / 4.0f), - 0, - m->floor->normal.y * (m->vel[2] / 4.0f), - }; + Vec3f step = { 0 }; + if (m->floor) { + step[0] = m->floor->normal.y * (m->vel[0] / 4.0f); + step[2] = m->floor->normal.y * (m->vel[2] / 4.0f); + } intendedPos[0] = m->pos[0] + step[0]; intendedPos[1] = m->pos[1]; @@ -678,7 +680,7 @@ void apply_vertical_wind(struct MarioState *m) { if (m->action != ACT_GROUND_POUND) { offsetY = m->pos[1] - -1500.0f; - if (m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f) { + if (m->floor && m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f) { if (offsetY >= 0.0f) { maxVelY = 10000.0f / (offsetY + 200.0f); } else { diff --git a/src/game/rumble_init.c b/src/game/rumble_init.c index 73ffb21f..d779c2f9 100644 --- a/src/game/rumble_init.c +++ b/src/game/rumble_init.c @@ -106,7 +106,7 @@ static void update_rumble_pak(void) { if (gCurrRumbleSettings.unk0A >= 5) { start_rumble(); - } else if ((gCurrRumbleSettings.unk0A >= 2) && (gNumVblanks % gCurrRumbleSettings.unk0C == 0)) { + } else if ((gCurrRumbleSettings.unk0A >= 2) && gCurrRumbleSettings.unk0C && (gNumVblanks % gCurrRumbleSettings.unk0C == 0)) { start_rumble(); } else { stop_rumble();