Skip to content

Commit

Permalink
check not null before accessing by index (#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m authored Dec 24, 2021
1 parent f66ae23 commit dcc0791
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/rmodels.c
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ void UnloadMesh(Mesh mesh)
// Unload rlgl mesh vboId data
rlUnloadVertexArray(mesh.vaoId);

for (int i = 0; i < MAX_MESH_VERTEX_BUFFERS; i++) rlUnloadVertexBuffer(mesh.vboId[i]);
if (mesh.vboId != NULL) for (int i = 0; i < MAX_MESH_VERTEX_BUFFERS; i++) rlUnloadVertexBuffer(mesh.vboId[i]);
RL_FREE(mesh.vboId);

RL_FREE(mesh.vertices);
Expand Down Expand Up @@ -1787,9 +1787,12 @@ void UnloadMaterial(Material material)
if (material.shader.id != rlGetShaderIdDefault()) UnloadShader(material.shader);

// Unload loaded texture maps (avoid unloading default texture, managed by raylib)
for (int i = 0; i < MAX_MATERIAL_MAPS; i++)
if (material.maps != NULL)
{
if (material.maps[i].texture.id != rlGetTextureIdDefault()) rlUnloadTexture(material.maps[i].texture.id);
for (int i = 0; i < MAX_MATERIAL_MAPS; i++)
{
if (material.maps[i].texture.id != rlGetTextureIdDefault()) rlUnloadTexture(material.maps[i].texture.id);
}
}

RL_FREE(material.maps);
Expand Down

0 comments on commit dcc0791

Please sign in to comment.