Return -1 instead of crashing if no floor under mario on create
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h> // For printf before exit, TODO remove
|
|
||||||
|
|
||||||
#include "../shim.h"
|
#include "../shim.h"
|
||||||
#include "../include/PR/os_cont.h"
|
#include "../include/PR/os_cont.h"
|
||||||
@@ -1797,7 +1796,7 @@ s32 execute_mario_action(UNUSED struct Object *o) {
|
|||||||
* INITIALIZATION *
|
* INITIALIZATION *
|
||||||
**************************************************/
|
**************************************************/
|
||||||
|
|
||||||
void init_mario(void) {
|
int init_mario(void) {
|
||||||
//Vec3s capPos;
|
//Vec3s capPos;
|
||||||
//struct Object *capObject;
|
//struct Object *capObject;
|
||||||
|
|
||||||
@@ -1843,12 +1842,10 @@ void init_mario(void) {
|
|||||||
gMarioState->floorHeight =
|
gMarioState->floorHeight =
|
||||||
find_floor(gMarioState->pos[0], gMarioState->pos[1], gMarioState->pos[2], &gMarioState->floor);
|
find_floor(gMarioState->pos[0], gMarioState->pos[1], gMarioState->pos[2], &gMarioState->floor);
|
||||||
|
|
||||||
if( gMarioState->floor == NULL ) {
|
if (gMarioState->floor != NULL) {
|
||||||
printf("Couldn't find floor!\n");
|
gMarioState->curTerrain = gMarioState->floor->terrain;
|
||||||
}
|
}
|
||||||
|
|
||||||
gMarioState->curTerrain = gMarioState->floor->terrain;
|
|
||||||
|
|
||||||
if (gMarioState->pos[1] < gMarioState->floorHeight) {
|
if (gMarioState->pos[1] < gMarioState->floorHeight) {
|
||||||
gMarioState->pos[1] = gMarioState->floorHeight;
|
gMarioState->pos[1] = gMarioState->floorHeight;
|
||||||
}
|
}
|
||||||
@@ -1886,6 +1883,8 @@ void init_mario(void) {
|
|||||||
capObject->oMoveAngleYaw = 0;
|
capObject->oMoveAngleYaw = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return gMarioState->floor != NULL ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_mario_from_save_file(void) {
|
void init_mario_from_save_file(void) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ s32 check_common_hold_action_exits(struct MarioState *m);
|
|||||||
s32 transition_submerged_to_walking(struct MarioState *m);
|
s32 transition_submerged_to_walking(struct MarioState *m);
|
||||||
s32 set_water_plunge_action(struct MarioState *m);
|
s32 set_water_plunge_action(struct MarioState *m);
|
||||||
s32 execute_mario_action(UNUSED struct Object *o);
|
s32 execute_mario_action(UNUSED struct Object *o);
|
||||||
void init_mario(void);
|
int init_mario(void);
|
||||||
void init_mario_from_save_file(void);
|
void init_mario_from_save_file(void);
|
||||||
|
|
||||||
#endif // MARIO_H
|
#endif // MARIO_H
|
||||||
|
|||||||
+7
-1
@@ -158,7 +158,13 @@ SM64_LIB_FN int32_t sm64_mario_create( int16_t x, int16_t y, int16_t z )
|
|||||||
gMarioSpawnInfoVal.next = NULL;
|
gMarioSpawnInfoVal.next = NULL;
|
||||||
|
|
||||||
init_mario_from_save_file();
|
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);
|
set_mario_action( gMarioState, ACT_SPAWN_SPIN_AIRBORNE, 0);
|
||||||
find_floor( x, y, z, &gMarioState->floor );
|
find_floor( x, y, z, &gMarioState->floor );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user