From a35d759a463ffee3acda5c735fc4d6ae16bb7115 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sun, 27 Feb 2022 00:53:58 -0800 Subject: [PATCH] Fix crash when surfaces fail to allocate --- src/engine/surface_load.c | 2 ++ src/pc/lua/smlua_obj_utils.c | 1 + 2 files changed, 3 insertions(+) diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index 3bf7a9c4f..0645f3110 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -71,6 +71,7 @@ static struct Surface *alloc_surface(void) { // we, um... // Perhaps originally just debug feedback? if (gSurfacesAllocated >= sSurfacePoolSize) { + return NULL; } surface->type = 0; @@ -363,6 +364,7 @@ static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) { nz *= mag; surface = alloc_surface(); + if (surface == NULL) { return NULL; } vec3s_copy(surface->prevVertex1, surface->vertex1); vec3s_copy(surface->prevVertex2, surface->vertex2); diff --git a/src/pc/lua/smlua_obj_utils.c b/src/pc/lua/smlua_obj_utils.c index 387709417..74dfba9bf 100644 --- a/src/pc/lua/smlua_obj_utils.c +++ b/src/pc/lua/smlua_obj_utils.c @@ -22,6 +22,7 @@ static struct Object* spawn_object_internal(enum BehaviorId behaviorId, enum Mod } struct Object* obj = spawn_object(gMarioStates[0].marioObj, loadedModelId, behavior); + if (obj == NULL) { LOG_ERROR("failed to allocate object"); return NULL;