From c2f591b9301cb5e6da1f9903618f18f03255ccf7 Mon Sep 17 00:00:00 2001 From: MysterD Date: Wed, 17 May 2023 17:48:54 -0700 Subject: [PATCH] Fix crash in packet_spawn_star --- src/pc/network/packets/packet_spawn_star.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pc/network/packets/packet_spawn_star.c b/src/pc/network/packets/packet_spawn_star.c index ed41f696..72fc4bb9 100644 --- a/src/pc/network/packets/packet_spawn_star.c +++ b/src/pc/network/packets/packet_spawn_star.c @@ -37,16 +37,21 @@ void network_receive_spawn_star(struct Packet* p) { packet_read(p, &behParams, sizeof(u32)); packet_read(p, &networkPlayerIndex, sizeof(u8)); - u32 oldBehParams = gCurrentObject->oBehParams; - gCurrentObject->oBehParams = behParams; + struct Object* oldObject = gCurrentObject; struct Object* o = NULL; - switch (starType) { - case 0: o = spawn_default_star(x, y, z); break; - case 1: o = spawn_red_coin_cutscene_star(x, y, z); break; - case 2: o = spawn_no_exit_star(x, y, z); break; - default: LOG_ERROR("UNKNOWN SPAWN STAR %d", starType); + gCurrentObject = gMarioStates[0].marioObj; + if (gCurrentObject) { + u32 oldBehParams = gCurrentObject->oBehParams; + gCurrentObject->oBehParams = behParams; + switch (starType) { + case 0: o = spawn_default_star(x, y, z); break; + case 1: o = spawn_red_coin_cutscene_star(x, y, z); break; + case 2: o = spawn_no_exit_star(x, y, z); break; + default: LOG_ERROR("UNKNOWN SPAWN STAR %d", starType); + } + gCurrentObject->oBehParams = oldBehParams; } - gCurrentObject->oBehParams = oldBehParams; + gCurrentObject = oldObject; if (o != NULL) { packet_read(p, &o->oPosX, sizeof(u32) * 3);