From 0e998a672ad07d1182fd3f790ec3de1e4cf007c0 Mon Sep 17 00:00:00 2001 From: Sunketchupm Date: Fri, 13 Mar 2026 10:16:40 -0400 Subject: [PATCH] Add object limit to reduce chances of breaking --- autogen/lua_definitions/constants.lua | 2 +- src/game/object_list_processor.h | 3 +-- src/game/spawn_object.c | 15 +++++++++++---- src/pc/lua/smlua_constants_autogen.c | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index adde37875..260ef7cc9 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -6668,7 +6668,7 @@ TIME_STOP_MARIO_OPENED_DOOR = (1 << 5) TIME_STOP_ACTIVE = (1 << 6) --- @type integer -OBJECT_POOL_CAPACITY = 0xFFFFFFFF +OBJECT_POOL_CAPACITY = 4096 --- @type integer OBJECT_POOL_NODE_CAPACITY = 256 diff --git a/src/game/object_list_processor.h b/src/game/object_list_processor.h index 07f33ee23..70b8ffcaf 100644 --- a/src/game/object_list_processor.h +++ b/src/game/object_list_processor.h @@ -22,9 +22,8 @@ /** * The maximum number of objects that can be loaded at once. - * Kept for compatibility, but is unused. */ -#define OBJECT_POOL_CAPACITY 0xFFFFFFFF +#define OBJECT_POOL_CAPACITY 4096 /** * The maximum number of objects that can be in a single pool node. * A higher number might be better for less fragmentation. diff --git a/src/game/spawn_object.c b/src/game/spawn_object.c index 0fb892535..7053170e0 100644 --- a/src/game/spawn_object.c +++ b/src/game/spawn_object.c @@ -108,12 +108,15 @@ struct Object* try_allocate_object(struct ObjectNode* destList, struct ObjectPoo } destList->prev = nextObj; } else { - if (node->next != NULL) { - return try_allocate_object(destList, node->next); + if (gPrevFrameObjectCount > OBJECT_POOL_CAPACITY) { + return NULL; + } + + if (node->next == NULL) { + node->next = (struct ObjectPoolNode*)calloc(1, sizeof(struct ObjectPoolNode)); + reinit_objects(node->next); } - node->next = (struct ObjectPoolNode*)calloc(1, sizeof(struct ObjectPoolNode)); - reinit_objects(node->next); return try_allocate_object(destList, node->next); } @@ -288,6 +291,10 @@ struct Object *allocate_object(struct ObjectNode *objList) { // If an unimportant object does exist, unload it and take its slot. unload_object(unimportantObj); obj = try_allocate_object(objList, &gObjectPool); + if (obj == NULL) { + return NULL; + } + if (gCurrentObject == obj) { //! Uh oh, the unimportant object was in the middle of // updating! This could cause some interesting logic errors, diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 4179649f3..aa1107af2 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -2976,7 +2976,7 @@ char gSmluaConstants[] = "" "TIME_STOP_ALL_OBJECTS=(1 << 4)\n" "TIME_STOP_MARIO_OPENED_DOOR=(1 << 5)\n" "TIME_STOP_ACTIVE=(1 << 6)\n" -"OBJECT_POOL_CAPACITY=0xFFFFFFFF\n" +"OBJECT_POOL_CAPACITY=4096\n" "OBJECT_POOL_NODE_CAPACITY=256\n" "OBJ_LIST_PLAYER=0\n" "OBJ_LIST_EXT=1\n"