Prevent hang due to mirror mario nodes

This commit is contained in:
MysterD 2020-10-04 22:10:41 -07:00
parent 70fdad4e7c
commit 6f23b63e61
4 changed files with 25 additions and 2 deletions

View file

@ -546,6 +546,28 @@ struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *chil
return childNode;
}
struct GraphNode* geo_remove_child_from_parent(struct GraphNode* parent, struct GraphNode* graphNode) {
struct GraphNode** firstChild;
firstChild = &parent->children;
// Remove link with siblings
graphNode->prev->next = graphNode->next;
graphNode->next->prev = graphNode->prev;
// If this node was the first child, a new first child must be chosen
if (*firstChild == graphNode) {
// The list is circular, so this checks whether it was the only child
if (graphNode->next == graphNode) {
*firstChild = NULL; // Parent has no children anymore
}
else {
*firstChild = graphNode->next; // Choose a new first child
}
}
return parent;
}
/**
* Remove a node from the scene graph. It changes the links with its
* siblings and with its parent, it doesn't deallocate the memory

View file

@ -421,6 +421,7 @@ struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *po
struct Object *objNode, Vec3s translation,
GraphNodeFunc nodeFunc, s32 playerIndex);
struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode);
struct GraphNode* geo_remove_child_from_parent(struct GraphNode* parent, struct GraphNode* graphNode);
struct GraphNode *geo_remove_child(struct GraphNode *graphNode);
struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild);

View file

@ -644,7 +644,7 @@ Gfx* geo_render_mirror_mario(s32 callContext, struct GraphNode* node, UNUSED Mat
geo_add_child(node, &gMirrorMario[i].node);
break;
case GEO_CONTEXT_AREA_UNLOAD:
geo_remove_child(&gMirrorMario[i].node);
geo_remove_child_from_parent(node, &gMirrorMario[i].node);
break;
case GEO_CONTEXT_RENDER:
if (mario->header.gfx.pos[0] > 1700.0f) {

View file

@ -7,7 +7,7 @@
#ifdef DEBUG
static u8 warpToLevel = LEVEL_BOB;
static u8 warpToLevel = LEVEL_LLL;
#define SCANCODE_0 0x0B
#define SCANCODE_1 0x02