Reviewed to work on Raspberry Pi

[rlgl] Extensions strings loading was redone to avoid a Segmentation
Fault on Raspberry Pi
This commit is contained in:
raysan5 2015-09-02 01:08:41 +02:00
parent e28fef6ee0
commit 4879106096
6 changed files with 94 additions and 118 deletions

View file

@ -584,6 +584,7 @@ Model LoadModel(const char *fileName)
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
free(vData.colors);
}
}
@ -619,10 +620,10 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
vData.vertexCount = numTriangles*3;
vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount * 2 * sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char)); // Not used...
vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char)); // Not used...
int vCounter = 0; // Used to count vertices float by float
int tcCounter = 0; // Used to count texcoords float by float
@ -722,6 +723,7 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
free(vData.colors);
}
return model;
@ -1038,10 +1040,10 @@ Model LoadCubicmap(Image cubicmap)
// Move data from mapVertices temp arays to vertices float array
vData.vertexCount = vCounter;
vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount * 2 * sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char)); // Not used...
vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char)); // Not used...
// Fill color data
// NOTE: Not used any more... just one plain color defined at DrawModel()
@ -1096,6 +1098,7 @@ Model LoadCubicmap(Image cubicmap)
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
free(vData.colors);
}
return model;
@ -1117,7 +1120,8 @@ void UnloadModel(Model model)
rlDeleteVertexArrays(model.mesh.vaoId);
TraceLog(INFO, "Unloaded model data");
if (model.mesh.vaoId > 0) TraceLog(INFO, "[VAO ID %i] Unloaded model data from VRAM (GPU)", model.mesh.vaoId);
else TraceLog(INFO, "[VBO ID %i][VBO ID %i][VBO ID %i] Unloaded model data from VRAM (GPU)", model.mesh.vboId[0], model.mesh.vboId[1], model.mesh.vboId[2]);
}
// Link a texture to a model
@ -1718,10 +1722,10 @@ static VertexData LoadOBJ(const char *fileName)
vData.vertexCount = numTriangles*3;
// Additional arrays to store vertex data as floats
vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount * 2 * sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char));
vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char));
int vCounter = 0; // Used to count vertices float by float
int tcCounter = 0; // Used to count texcoords float by float