From feee5eb5697c69fa854acc0a35c1f6b72bef47c6 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 16 Jun 2023 17:19:18 -0700 Subject: [PATCH] Fixed more memory corruption with object collisions --- src/engine/surface_load.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index 14eb0cbaa..385d48430 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -756,7 +756,10 @@ void load_object_collision_model(void) { if (!gCurrentObject) { return; } if (gCurrentObject->collisionData == NULL) { return; } - s32 numVertices = *gCurrentObject->collisionData; + s32 numVertices = 64; + if (gCurrentObject->collisionData[0] == COL_INIT()) { + numVertices = gCurrentObject->collisionData[1]; + } if (numVertices <= 0) { LOG_ERROR("Object collisions had invalid vertex count"); return; @@ -769,7 +772,9 @@ void load_object_collision_model(void) { if (numVertices > sVertexDataCount || sVertexData == NULL) { if (sVertexData) { free(sVertexData); } sVertexDataCount = numVertices; - sVertexData = malloc(sizeof(s16) * sVertexDataCount); + if (sVertexDataCount < 64) { sVertexDataCount = 64; } + sVertexData = malloc((3 * sVertexDataCount + 1) * sizeof(s16)); + LOG_INFO("Reallocating object vertex data: %u", sVertexDataCount); } s16* collisionData = gCurrentObject->collisionData;