Browse Source

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()?
Ray 7 years ago
parent
commit
6d64327a87
1 changed files with 4 additions and 5 deletions
  1. 4 5
      src/models.c

+ 4 - 5
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); 
     }
 }