diff --git a/src/pc/controller/controller_keyboard_debug.c b/src/pc/controller/controller_keyboard_debug.c index 960496ad..4dc0e107 100644 --- a/src/pc/controller/controller_keyboard_debug.c +++ b/src/pc/controller/controller_keyboard_debug.c @@ -139,7 +139,10 @@ static void debug_reload_lua(void) { static void debug_spawn_object(void) { struct Object* box = spawn_object(gMarioStates[0].marioObj, MODEL_BREAKABLE_BOX_SMALL, bhvBreakableBoxSmall); - network_set_sync_id(box); + if (!network_set_sync_id(box)) { + box->activeFlags = ACTIVE_FLAG_DEACTIVATED; + return; + } struct Object* spawn_objects[] = { box }; u32 models[] = { MODEL_BREAKABLE_BOX_SMALL }; diff --git a/src/pc/network/packets/packet.h b/src/pc/network/packets/packet.h index 3886fc6b..64629e03 100644 --- a/src/pc/network/packets/packet.h +++ b/src/pc/network/packets/packet.h @@ -173,7 +173,7 @@ void network_init_object_field(struct Object* o, void* field); bool network_owns_object(struct Object* o); bool network_sync_object_initialized(struct Object* o); void network_clear_sync_objects(void); -void network_set_sync_id(struct Object* o); +bool network_set_sync_id(struct Object* o); void network_send_object(struct Object* o); void network_send_object_reliability(struct Object* o, bool reliable); void network_receive_object(struct Packet* p); diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index eb2508e0..dffc9192 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -112,7 +112,11 @@ void network_override_object(u8 syncId, struct Object* o) { struct SyncObject* network_init_object(struct Object *o, float maxSyncDistance) { // generate new sync ID - network_set_sync_id(o); + if (!network_set_sync_id(o)) { + LOG_ERROR("failed to sync id for object w/behavior %d", get_id_from_behavior(o->behavior)); + o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + return NULL; + } // set default values for sync object struct SyncObject* so = &gSyncObjects[o->oSyncID]; @@ -149,7 +153,8 @@ struct SyncObject* network_init_object(struct Object *o, float maxSyncDistance) } void network_init_object_field(struct Object *o, void* field) { - SOFT_ASSERT(o->oSyncID != 0); + if (o->oSyncID == 0) { return; } + // remember to synchronize this extra field struct SyncObject* so = &gSyncObjects[o->oSyncID]; u8 index = so->extraFieldCount++; @@ -204,8 +209,8 @@ u8 network_find_cached_sync_id(struct Object* o) { return 0; } -void network_set_sync_id(struct Object* o) { - if (o->oSyncID != 0) { return; } +bool network_set_sync_id(struct Object* o) { + if (o->oSyncID != 0) { return true; } u8 syncId = 0; if (!gNetworkAreaLoaded) { @@ -231,8 +236,11 @@ void network_set_sync_id(struct Object* o) { syncId = reservation_area_local_grab_id(); } - SOFT_ASSERT(syncId != 0); - SOFT_ASSERT(gSyncObjects[syncId].o == NULL); + if (syncId == 0) { + LOG_ERROR("failed to sync id for object w/behavior %d", get_id_from_behavior(o->behavior)); + return false; + } + SOFT_ASSERT_RETURN(gSyncObjects[syncId].o == NULL, false); o->oSyncID = syncId; @@ -240,7 +248,8 @@ void network_set_sync_id(struct Object* o) { LOG_INFO("set sync id for object w/behavior %d", get_id_from_behavior(o->behavior)); } - SOFT_ASSERT(o->oSyncID < MAX_SYNC_OBJECTS); + SOFT_ASSERT_RETURN(o->oSyncID < MAX_SYNC_OBJECTS, false); + return true; } // ----- header ----- // diff --git a/src/pc/network/packets/packet_request_failed.c b/src/pc/network/packets/packet_request_failed.c index 2c97d45c..22175a79 100644 --- a/src/pc/network/packets/packet_request_failed.c +++ b/src/pc/network/packets/packet_request_failed.c @@ -1,6 +1,6 @@ #include #include "../network.h" -#define DISABLE_MODULE_LOG 1 +//#define DISABLE_MODULE_LOG 1 #include "pc/debuglog.h" void network_send_request_failed(struct NetworkPlayer* toNp, u8 requestType) {