From be84cd333a7510bb963b27c5921d87e7fb907909 Mon Sep 17 00:00:00 2001 From: jaburns Date: Thu, 22 Jul 2021 21:25:02 -0600 Subject: [PATCH] Return -1 instead of crashing if no floor under mario on create --- src/decomp/game/mario.c | 11 +++++------ src/decomp/game/mario.h | 2 +- src/libsm64.c | 8 +++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/decomp/game/mario.c b/src/decomp/game/mario.c index e6ed2bb..34f2fc0 100644 --- a/src/decomp/game/mario.c +++ b/src/decomp/game/mario.c @@ -1,6 +1,5 @@ #include #include -#include // For printf before exit, TODO remove #include "../shim.h" #include "../include/PR/os_cont.h" @@ -1797,7 +1796,7 @@ s32 execute_mario_action(UNUSED struct Object *o) { * INITIALIZATION * **************************************************/ -void init_mario(void) { +int init_mario(void) { //Vec3s capPos; //struct Object *capObject; @@ -1843,12 +1842,10 @@ void init_mario(void) { gMarioState->floorHeight = find_floor(gMarioState->pos[0], gMarioState->pos[1], gMarioState->pos[2], &gMarioState->floor); - if( gMarioState->floor == NULL ) { - printf("Couldn't find floor!\n"); + if (gMarioState->floor != NULL) { + gMarioState->curTerrain = gMarioState->floor->terrain; } - gMarioState->curTerrain = gMarioState->floor->terrain; - if (gMarioState->pos[1] < gMarioState->floorHeight) { gMarioState->pos[1] = gMarioState->floorHeight; } @@ -1886,6 +1883,8 @@ void init_mario(void) { capObject->oMoveAngleYaw = 0; } #endif + + return gMarioState->floor != NULL ? 0 : -1; } void init_mario_from_save_file(void) { diff --git a/src/decomp/game/mario.h b/src/decomp/game/mario.h index e18b3d7..b4dfb16 100644 --- a/src/decomp/game/mario.h +++ b/src/decomp/game/mario.h @@ -48,7 +48,7 @@ s32 check_common_hold_action_exits(struct MarioState *m); s32 transition_submerged_to_walking(struct MarioState *m); s32 set_water_plunge_action(struct MarioState *m); s32 execute_mario_action(UNUSED struct Object *o); -void init_mario(void); +int init_mario(void); void init_mario_from_save_file(void); #endif // MARIO_H diff --git a/src/libsm64.c b/src/libsm64.c index dce6515..9df87a6 100644 --- a/src/libsm64.c +++ b/src/libsm64.c @@ -158,7 +158,13 @@ SM64_LIB_FN int32_t sm64_mario_create( int16_t x, int16_t y, int16_t z ) gMarioSpawnInfoVal.next = NULL; init_mario_from_save_file(); - init_mario(); + + if( init_mario() < 0 ) + { + sm64_mario_delete( marioIndex ); + return -1; + } + set_mario_action( gMarioState, ACT_SPAWN_SPIN_AIRBORNE, 0); find_floor( x, y, z, &gMarioState->floor );