aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2015-08-03 17:27:04 +0200
committerraysan5 <raysan5@gmail.com>2015-08-03 17:27:04 +0200
commit36552ff995e402c4acff6261d42541732febf10b (patch)
tree926d3e6a0d668d378d2b880da7d2f342c7d8f9bf /src
parent0af2f4581531db26c153e97a3fe18c373b93926f (diff)
downloadraylib-36552ff995e402c4acff6261d42541732febf10b.tar.gz
raylib-36552ff995e402c4acff6261d42541732febf10b.zip
Added security check if file not found
Diffstat (limited to 'src')
-rw-r--r--src/models.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/models.c b/src/models.c
index 862d96cc..81f3db68 100644
--- a/src/models.c
+++ b/src/models.c
@@ -558,22 +558,33 @@ void DrawGizmo(Vector3 position)
Model LoadModel(const char *fileName)
{
VertexData vData;
+
+ Model model;
+
+ // TODO: Initialize default data for model in case loading fails, maybe a cube?
if (strcmp(GetExtension(fileName),"obj") == 0) vData = LoadOBJ(fileName);
else TraceLog(WARNING, "[%s] Model extension not recognized, it can't be loaded", fileName);
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
-
- // NOTE: model properties (transform, texture, shader) are initialized inside rlglLoadModel()
- Model model = rlglLoadModel(vData); // Upload vertex data to GPU
-
- // Now that vertex data is uploaded to GPU, we can free arrays
- // NOTE: We don't need CPU vertex data on OpenGL 3.3 or ES2
- if (rlGetVersion() != OPENGL_11)
+
+ if (vData.vertexCount == 0)
{
- free(vData.vertices);
- free(vData.texcoords);
- free(vData.normals);
+ TraceLog(WARNING, "Model could not be loaded");
+ }
+ else
+ {
+ // NOTE: model properties (transform, texture, shader) are initialized inside rlglLoadModel()
+ model = rlglLoadModel(vData); // Upload vertex data to GPU
+
+ // Now that vertex data is uploaded to GPU, we can free arrays
+ // NOTE: We don't need CPU vertex data on OpenGL 3.3 or ES2
+ if (rlGetVersion() != OPENGL_11)
+ {
+ free(vData.vertices);
+ free(vData.texcoords);
+ free(vData.normals);
+ }
}
return model;