Fixed more memory corruption with object collisions

This commit is contained in:
MysterD 2023-06-16 17:19:18 -07:00
parent b3cae34234
commit feee5eb569
1 changed files with 7 additions and 2 deletions

View File

@ -756,7 +756,10 @@ void load_object_collision_model(void) {
if (!gCurrentObject) { return; } if (!gCurrentObject) { return; }
if (gCurrentObject->collisionData == NULL) { 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) { if (numVertices <= 0) {
LOG_ERROR("Object collisions had invalid vertex count"); LOG_ERROR("Object collisions had invalid vertex count");
return; return;
@ -769,7 +772,9 @@ void load_object_collision_model(void) {
if (numVertices > sVertexDataCount || sVertexData == NULL) { if (numVertices > sVertexDataCount || sVertexData == NULL) {
if (sVertexData) { free(sVertexData); } if (sVertexData) { free(sVertexData); }
sVertexDataCount = numVertices; 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; s16* collisionData = gCurrentObject->collisionData;