defensive crash fix in smlua_model_util_get_id
Some checks are pending
Build coop / build-linux (push) Waiting to run
Build coop / build-steamos (push) Waiting to run
Build coop / build-windows (push) Waiting to run
Build coop / build-macos-arm (push) Waiting to run
Build coop / build-macos-intel (push) Waiting to run

This commit is contained in:
Isaac0-dev 2026-05-19 16:24:19 +10:00
parent 834512a5c5
commit 3bd5dc842f

View file

@ -594,6 +594,14 @@ enum ModelExtendedId smlua_model_util_get_id(const char* name) {
}
}
if (!sCustomModels) {
smlua_model_util_initialize();
if (!sCustomModels) {
LOG_LUA("Failed to initialize custom models!");
return E_MODEL_ERROR_MODEL;
}
}
// If we've extended past our current custom model limit. Reallocate so we have more space.
if (sCustomModelsCount >= sMaxCustomModelsCount) {
if (sMaxCustomModelsCount + CUSTOM_MODEL_CHUNK_SIZE >= 0xFFFF) {
@ -603,6 +611,10 @@ enum ModelExtendedId smlua_model_util_get_id(const char* name) {
sMaxCustomModelsCount += CUSTOM_MODEL_CHUNK_SIZE;
sCustomModels = (struct ModelUtilsInfo *)realloc(sCustomModels, sMaxCustomModelsCount * sizeof(struct ModelUtilsInfo));
}
if (!sCustomModels) {
LOG_LUA("Failed to allocate custom model: '%s'", name);
return E_MODEL_ERROR_MODEL;
}
// Allocate custom model
u16 customIndex = sCustomModelsCount++;