fix dynamic custom model alloc

This commit is contained in:
Isaac0-dev 2025-02-13 13:17:10 +10:00
parent e9c6368210
commit a0ad607b4e

View file

@ -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