Fix crashes and errors when exit-to-castle isn't set properly

This commit is contained in:
MysterD 2023-06-03 01:50:41 -07:00
parent 2fa506d774
commit 40dfbb7589
4 changed files with 27 additions and 7 deletions

View file

@ -172,6 +172,21 @@ struct ObjectWarpNode *area_get_warp_node(u8 id) {
return node; return node;
} }
struct ObjectWarpNode *area_get_any_warp_node(void) {
if (!gCurrentArea || !gCurrentArea->warpNodes) { return NULL; }
struct ObjectWarpNode *node = NULL;
struct ObjectWarpNode *pick = NULL;
for (node = gCurrentArea->warpNodes; node != NULL; node = node->next) {
if (node->node.destLevel != gCurrLevelNum) { continue; }
if (!pick) { pick = node; continue; }
if (node->node.destArea < pick->node.destArea) { pick = node; }
}
return pick;
}
struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o) { struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o) {
if (o == NULL) { return NULL; } if (o == NULL) { return NULL; }

View file

@ -157,6 +157,7 @@ void override_viewport_and_clip(Vp *a, Vp *b, u8 c, u8 d, u8 e);
void print_intro_text(void); void print_intro_text(void);
u32 get_mario_spawn_type(struct Object *o); u32 get_mario_spawn_type(struct Object *o);
struct ObjectWarpNode *area_get_warp_node(u8 id); struct ObjectWarpNode *area_get_warp_node(u8 id);
struct ObjectWarpNode *area_get_any_warp_node(void);
struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o); struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o);
void clear_areas(void); void clear_areas(void);
void clear_area_graph_nodes(void); void clear_area_graph_nodes(void);

View file

@ -405,7 +405,9 @@ void init_mario_after_warp(void) {
struct ObjectWarpNode *spawnNode = area_get_warp_node(sWarpDest.nodeId); struct ObjectWarpNode *spawnNode = area_get_warp_node(sWarpDest.nodeId);
if (spawnNode == NULL || spawnNode->object == NULL) { spawnNode = area_get_warp_node(0xFA); } if (spawnNode == NULL || spawnNode->object == NULL) { spawnNode = area_get_warp_node(0xFA); }
if (spawnNode == NULL || spawnNode->object == NULL) { spawnNode = area_get_warp_node(0x00); } if (spawnNode == NULL || spawnNode->object == NULL) { spawnNode = area_get_warp_node(0x00); }
if (spawnNode == NULL || spawnNode->object == NULL) { spawnNode = area_get_any_warp_node(); }
if (spawnNode == NULL || spawnNode->object == NULL) { return; } if (spawnNode == NULL || spawnNode->object == NULL) { return; }
u32 marioSpawnType = get_mario_spawn_type(spawnNode->object); u32 marioSpawnType = get_mario_spawn_type(spawnNode->object);
if (gMarioState && gMarioState->action != ACT_UNINITIALIZED) { if (gMarioState && gMarioState->action != ACT_UNINITIALIZED) {

View file

@ -1782,7 +1782,7 @@ Gfx *geo_painting_draw(s32 callContext, struct GraphNode *node, UNUSED void *con
* Update the painting system's local copy of Mario's current floor and position. * Update the painting system's local copy of Mario's current floor and position.
*/ */
Gfx *geo_painting_update(s32 callContext, UNUSED struct GraphNode *node, UNUSED Mat4 c) { Gfx *geo_painting_update(s32 callContext, UNUSED struct GraphNode *node, UNUSED Mat4 c) {
struct Surface *surface; struct Surface *surface = NULL;
// Reset the update counter // Reset the update counter
if (callContext != GEO_CONTEXT_RENDER) { if (callContext != GEO_CONTEXT_RENDER) {
@ -1793,6 +1793,7 @@ Gfx *geo_painting_update(s32 callContext, UNUSED struct GraphNode *node, UNUSED
gPaintingUpdateCounter = gAreaUpdateCounter; gPaintingUpdateCounter = gAreaUpdateCounter;
// Store Mario's floor and position // Store Mario's floor and position
if (gMarioObject) {
find_floor(gMarioObject->oPosX, gMarioObject->oPosY, gMarioObject->oPosZ, &surface); find_floor(gMarioObject->oPosX, gMarioObject->oPosY, gMarioObject->oPosZ, &surface);
if (surface != NULL) { if (surface != NULL) {
gPaintingMarioFloorType = surface->type; gPaintingMarioFloorType = surface->type;
@ -1801,5 +1802,6 @@ Gfx *geo_painting_update(s32 callContext, UNUSED struct GraphNode *node, UNUSED
gPaintingMarioYPos = gMarioObject->oPosY; gPaintingMarioYPos = gMarioObject->oPosY;
gPaintingMarioZPos = gMarioObject->oPosZ; gPaintingMarioZPos = gMarioObject->oPosZ;
} }
}
return NULL; return NULL;
} }