Return -1 instead of crashing if no floor under mario on create

This commit is contained in:
jaburns
2021-07-22 21:25:02 -06:00
parent 8144865975
commit be84cd333a
3 changed files with 13 additions and 8 deletions
+5 -6
View File
@@ -1,6 +1,5 @@
#include <stdlib.h>
#include <math.h>
#include <stdio.h> // 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,11 +1842,9 @@ 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;
}
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) {
+1 -1
View File
@@ -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
+7 -1
View File
@@ -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 );