aboutsummaryrefslogtreecommitdiff
path: root/src/models.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/models.c')
-rw-r--r--src/models.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/models.c b/src/models.c
index 7d24e383..066b919e 100644
--- a/src/models.c
+++ b/src/models.c
@@ -553,7 +553,7 @@ Model LoadModel(const char *fileName)
if (model.mesh.vertexCount == 0) TraceLog(WARNING, "Model could not be loaded");
else
{
- rlglLoadMesh(&model.mesh); // Upload vertex data to GPU
+ rlglLoadMesh(&model.mesh); // Upload vertex data to GPU
model.transform = MatrixIdentity();
model.material = LoadDefaultMaterial();
@@ -567,7 +567,9 @@ Model LoadModelEx(Mesh data)
{
Model model = { 0 };
- rlglLoadMesh(&data); // Upload vertex data to GPU
+ model.mesh = data;
+
+ rlglLoadMesh(&model.mesh); // Upload vertex data to GPU
model.transform = MatrixIdentity();
model.material = LoadDefaultMaterial();
@@ -693,12 +695,13 @@ Model LoadCubicmap(Image cubicmap)
void UnloadModel(Model model)
{
// Unload mesh data
- free(model.mesh.vertices);
- free(model.mesh.texcoords);
+ if (model.mesh.vertices != NULL) free(model.mesh.vertices);
+ if (model.mesh.texcoords != NULL) free(model.mesh.texcoords);
if (model.mesh.normals != NULL) free(model.mesh.normals);
if (model.mesh.colors != NULL) free(model.mesh.colors);
if (model.mesh.tangents != NULL) free(model.mesh.tangents);
if (model.mesh.texcoords2 != NULL) free(model.mesh.texcoords2);
+ if (model.mesh.indices != NULL) free(model.mesh.indices);
TraceLog(INFO, "Unloaded model data from RAM (CPU)");
@@ -708,8 +711,11 @@ void UnloadModel(Model model)
rlDeleteBuffers(model.mesh.vboId[3]); // colors
rlDeleteBuffers(model.mesh.vboId[4]); // tangents
rlDeleteBuffers(model.mesh.vboId[5]); // texcoords2
+ rlDeleteBuffers(model.mesh.vboId[6]); // indices
rlDeleteVertexArrays(model.mesh.vaoId);
+
+ UnloadMaterial(model.material);
}
// Load material data (from file)
@@ -743,6 +749,13 @@ Material LoadDefaultMaterial(void)
return material;
}
+void UnloadMaterial(Material material)
+{
+ rlDeleteTextures(material.texDiffuse.id);
+ rlDeleteTextures(material.texNormal.id);
+ rlDeleteTextures(material.texSpecular.id);
+}
+
// Link a texture to a model
void SetModelTexture(Model *model, Texture2D texture)
{
@@ -2006,7 +2019,7 @@ static Material LoadMTL(const char *fileName)
char buffer[MAX_BUFFER_SIZE];
Vector3 color = { 1.0f, 1.0f, 1.0f };
- char *mapFileName;
+ char *mapFileName = NULL;
FILE *mtlFile;