Added security check if file not found
This commit is contained in:
parent
0af2f45815
commit
36552ff995
31
src/models.c
31
src/models.c
@ -558,22 +558,33 @@ void DrawGizmo(Vector3 position)
|
|||||||
Model LoadModel(const char *fileName)
|
Model LoadModel(const char *fileName)
|
||||||
{
|
{
|
||||||
VertexData vData;
|
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);
|
if (strcmp(GetExtension(fileName),"obj") == 0) vData = LoadOBJ(fileName);
|
||||||
else TraceLog(WARNING, "[%s] Model extension not recognized, it can't be loaded", 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: 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()
|
if (vData.vertexCount == 0)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
free(vData.vertices);
|
TraceLog(WARNING, "Model could not be loaded");
|
||||||
free(vData.texcoords);
|
}
|
||||||
free(vData.normals);
|
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;
|
return model;
|
||||||
|
Loading…
Reference in New Issue
Block a user