From a0ad607b4eb9e03e1984055c444fac694af19733 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Thu, 13 Feb 2025 13:17:10 +1000 Subject: [PATCH] fix dynamic custom model alloc --- src/pc/lua/utils/smlua_model_utils.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pc/lua/utils/smlua_model_utils.c b/src/pc/lua/utils/smlua_model_utils.c index e45cc7938..dbc4dcbd4 100644 --- a/src/pc/lua/utils/smlua_model_utils.c +++ b/src/pc/lua/utils/smlua_model_utils.c @@ -527,12 +527,13 @@ enum ModelExtendedId smlua_model_util_get_id(const char* name) { } // If we've extended past our current custom model limit. Reallocate so we have more space. - if (sCustomModelsCount >= sMaxCustomModelsCount && sMaxCustomModelsCount + CUSTOM_MODEL_CHUNK_SIZE < 65535) { + if (sCustomModelsCount >= sMaxCustomModelsCount) { + if (sMaxCustomModelsCount + CUSTOM_MODEL_CHUNK_SIZE < 0xFFFF) { + LOG_LUA("Failed to get model: '%s' (too many custom models!)", name); + return E_MODEL_ERROR_MODEL; + } sMaxCustomModelsCount += CUSTOM_MODEL_CHUNK_SIZE; sCustomModels = (struct ModelUtilsInfo *)realloc(sCustomModels, sMaxCustomModelsCount * sizeof(struct ModelUtilsInfo)); - } else { - LOG_LUA("Failed to get model: '%s' (too many custom models!)", name); - return E_MODEL_ERROR_MODEL; } // Allocate custom model