From 6d64327a874b09e93290d1525edd5347a9787b84 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 22 Feb 2018 12:39:17 +0100 Subject: [PATCH] Reviewed unloading model data When UnloadModel() --> UnloadMaterial(), avoid unloading default shader (if used) and avoid unlaoding default texture (if used), that data is managed by raylib internally. The question is... should UnloadModel() also UnloadMaterial()? --- src/models.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/models.c b/src/models.c index 1f37e3453..02e69c0c0 100644 --- a/src/models.c +++ b/src/models.c @@ -1671,14 +1671,13 @@ Material LoadMaterialDefault(void) // Unload material from memory void UnloadMaterial(Material material) { - // Unload material shader - UnloadShader(material.shader); + // Unload material shader (avoid unloading default shader, managed by raylib) + if (material.shader.id != GetShaderDefault().id) UnloadShader(material.shader); - // Unload loaded texture maps + // Unload loaded texture maps (avoid unloading default texture, managed by raylib) for (int i = 0; i < MAX_MATERIAL_MAPS; i++) { - // NOTE: We already check for (tex.id > 0) inside function - rlDeleteTextures(material.maps[i].texture.id); + if (material.maps[i].texture.id != GetTextureDefault().id) rlDeleteTextures(material.maps[i].texture.id); } }