Browse Source

Review all RL_CALLOC() calls

All data should be properly initialized by now
raysan5 6 years ago
parent
commit
c661cad692
4 changed files with 21 additions and 22 deletions
  1. 1 2
      examples/models/models_material_pbr.c
  2. 15 15
      src/models.c
  3. 1 1
      src/raudio.c
  4. 4 4
      src/rlgl.h

+ 1 - 2
examples/models/models_material_pbr.c

@@ -100,8 +100,7 @@ int main(void)
 
 
     // De-Initialization
     // De-Initialization
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
-    // TODO: Unload materials and shaders
-    
+    UnloadMaterial(model.materials[0]); // Unload material: shader and textures
     UnloadModel(model);         // Unload model
     UnloadModel(model);         // Unload model
 
 
     CloseWindow();              // Close window and OpenGL context
     CloseWindow();              // Close window and OpenGL context

+ 15 - 15
src/models.c

@@ -829,7 +829,7 @@ Material *LoadMaterials(const char *fileName, int *materialCount)
 Material LoadMaterialDefault(void)
 Material LoadMaterialDefault(void)
 {
 {
     Material material = { 0 };
     Material material = { 0 };
-    material.maps = (MaterialMap *)RL_CALLOC(MAX_MATERIAL_MAPS*sizeof(MaterialMap), 1);
+    material.maps = (MaterialMap *)RL_CALLOC(MAX_MATERIAL_MAPS, sizeof(MaterialMap));
 
 
     material.shader = GetShaderDefault();
     material.shader = GetShaderDefault();
     material.maps[MAP_DIFFUSE].texture = GetTextureDefault();   // White texture (1x1 pixel)
     material.maps[MAP_DIFFUSE].texture = GetTextureDefault();   // White texture (1x1 pixel)
@@ -1181,7 +1181,7 @@ bool IsModelAnimationValid(Model model, ModelAnimation anim)
 Mesh GenMeshPoly(int sides, float radius)
 Mesh GenMeshPoly(int sides, float radius)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
     int vertexCount = sides*3;
     int vertexCount = sides*3;
 
 
     // Vertices definition
     // Vertices definition
@@ -1244,7 +1244,7 @@ Mesh GenMeshPoly(int sides, float radius)
 Mesh GenMeshPlane(float width, float length, int resX, int resZ)
 Mesh GenMeshPlane(float width, float length, int resX, int resZ)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
 #define CUSTOM_MESH_GEN_PLANE
 #define CUSTOM_MESH_GEN_PLANE
 #if defined(CUSTOM_MESH_GEN_PLANE)
 #if defined(CUSTOM_MESH_GEN_PLANE)
@@ -1347,7 +1347,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
     mesh.vertices = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
     mesh.vertices = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
     mesh.texcoords = (float *)RL_MALLOC(plane->ntriangles*3*2*sizeof(float));
     mesh.texcoords = (float *)RL_MALLOC(plane->ntriangles*3*2*sizeof(float));
     mesh.normals = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
     mesh.normals = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int));
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
     mesh.vertexCount = plane->ntriangles*3;
     mesh.vertexCount = plane->ntriangles*3;
     mesh.triangleCount = plane->ntriangles;
     mesh.triangleCount = plane->ntriangles;
@@ -1379,7 +1379,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
 Mesh GenMeshCube(float width, float height, float length)
 Mesh GenMeshCube(float width, float height, float length)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
 #define CUSTOM_MESH_GEN_CUBE
 #define CUSTOM_MESH_GEN_CUBE
 #if defined(CUSTOM_MESH_GEN_CUBE)
 #if defined(CUSTOM_MESH_GEN_CUBE)
@@ -1545,7 +1545,7 @@ par_shapes_mesh* par_shapes_create_icosahedron();       // 20 sides polyhedron
 RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
 RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
     par_shapes_mesh *sphere = par_shapes_create_parametric_sphere(slices, rings);
     par_shapes_mesh *sphere = par_shapes_create_parametric_sphere(slices, rings);
     par_shapes_scale(sphere, radius, radius, radius);
     par_shapes_scale(sphere, radius, radius, radius);
@@ -1584,7 +1584,7 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
 RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
 RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
     par_shapes_mesh *sphere = par_shapes_create_hemisphere(slices, rings);
     par_shapes_mesh *sphere = par_shapes_create_hemisphere(slices, rings);
     par_shapes_scale(sphere, radius, radius, radius);
     par_shapes_scale(sphere, radius, radius, radius);
@@ -1623,7 +1623,7 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
 Mesh GenMeshCylinder(float radius, float height, int slices)
 Mesh GenMeshCylinder(float radius, float height, int slices)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
     // Instance a cylinder that sits on the Z=0 plane using the given tessellation
     // Instance a cylinder that sits on the Z=0 plane using the given tessellation
     // levels across the UV domain.  Think of "slices" like a number of pizza
     // levels across the UV domain.  Think of "slices" like a number of pizza
@@ -1682,7 +1682,7 @@ Mesh GenMeshCylinder(float radius, float height, int slices)
 Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
 Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
     if (radius > 1.0f) radius = 1.0f;
     if (radius > 1.0f) radius = 1.0f;
     else if (radius < 0.1f) radius = 0.1f;
     else if (radius < 0.1f) radius = 0.1f;
@@ -1725,7 +1725,7 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
 Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
 Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
     if (radius > 3.0f) radius = 3.0f;
     if (radius > 3.0f) radius = 3.0f;
     else if (radius < 0.5f) radius = 0.5f;
     else if (radius < 0.5f) radius = 0.5f;
@@ -1769,7 +1769,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
     #define GRAY_VALUE(c) ((c.r+c.g+c.b)/3)
     #define GRAY_VALUE(c) ((c.r+c.g+c.b)/3)
 
 
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
     int mapX = heightmap.width;
     int mapX = heightmap.width;
     int mapZ = heightmap.height;
     int mapZ = heightmap.height;
@@ -1878,7 +1878,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
 Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
 Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
 {
 {
     Mesh mesh = { 0 };
     Mesh mesh = { 0 };
-    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+    mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
     Color *cubicmapPixels = GetImageData(cubicmap);
     Color *cubicmapPixels = GetImageData(cubicmap);
 
 
@@ -2819,7 +2819,7 @@ static Model LoadOBJ(const char *fileName)
             mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
             mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
             mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
             mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
             mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
             mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
-            mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+            mesh.vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
             int vCount = 0;
             int vCount = 0;
             int vtCount = 0;
             int vtCount = 0;
@@ -3089,7 +3089,7 @@ static Model LoadIQM(const char *fileName)
         model.meshes[i].animVertices = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3);
         model.meshes[i].animVertices = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3);
         model.meshes[i].animNormals = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3);
         model.meshes[i].animNormals = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3);
         
         
-        model.meshes[i].vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+        model.meshes[i].vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
     }
     }
 
 
     // Triangles data processing
     // Triangles data processing
@@ -3411,7 +3411,7 @@ static Model LoadGLTF(const char *fileName)
         model.materials = RL_MALLOC(model.materialCount*sizeof(Material));
         model.materials = RL_MALLOC(model.materialCount*sizeof(Material));
         model.meshMaterial = RL_MALLOC(model.meshCount*sizeof(int));
         model.meshMaterial = RL_MALLOC(model.meshCount*sizeof(int));
         
         
-        for (int i = 0; i < model.meshCount; i++) model.meshes[i].vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO*sizeof(unsigned int), 1);
+        for (int i = 0; i < model.meshCount; i++) model.meshes[i].vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VBO, sizeof(unsigned int));
 
 
         for (int i = 0; i < model.materialCount - 1; i++)
         for (int i = 0; i < model.materialCount - 1; i++)
         {
         {

+ 1 - 1
src/raudio.c

@@ -591,7 +591,7 @@ void SetMasterVolume(float volume)
 // Create a new audio buffer. Initially filled with silence
 // Create a new audio buffer. Initially filled with silence
 AudioBuffer *InitAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_uint32 bufferSizeInFrames, int usage)
 AudioBuffer *InitAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_uint32 bufferSizeInFrames, int usage)
 {
 {
-    AudioBuffer *audioBuffer = (AudioBuffer *)RL_CALLOC(sizeof(*audioBuffer), 1);
+    AudioBuffer *audioBuffer = (AudioBuffer *)RL_CALLOC(1, sizeof(AudioBuffer));
     audioBuffer->buffer = RL_CALLOC((bufferSizeInFrames*channels*ma_get_bytes_per_sample(format)), 1);
     audioBuffer->buffer = RL_CALLOC((bufferSizeInFrames*channels*ma_get_bytes_per_sample(format)), 1);
     
     
     if (audioBuffer == NULL)
     if (audioBuffer == NULL)

+ 4 - 4
src/rlgl.h

@@ -1539,7 +1539,7 @@ void rlglInit(int width, int height)
 
 
     // NOTE: We have to duplicate string because glGetString() returns a const string
     // NOTE: We have to duplicate string because glGetString() returns a const string
     int len = strlen(extensions) + 1;
     int len = strlen(extensions) + 1;
-    char *extensionsDup = (char *)RL_CALLOC(len, 1);
+    char *extensionsDup = (char *)RL_CALLOC(len, sizeof(char));
     strcpy(extensionsDup, extensions);
     strcpy(extensionsDup, extensions);
     
     
     extList[numExt] = extensionsDup;
     extList[numExt] = extensionsDup;
@@ -2967,7 +2967,7 @@ char *LoadText(const char *fileName)
 Shader LoadShader(const char *vsFileName, const char *fsFileName)
 Shader LoadShader(const char *vsFileName, const char *fsFileName)
 {
 {
     Shader shader = { 0 };
     Shader shader = { 0 };
-    shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS*sizeof(int), 1);
+    shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS, sizeof(int));
 
 
     char *vShaderStr = NULL;
     char *vShaderStr = NULL;
     char *fShaderStr = NULL;
     char *fShaderStr = NULL;
@@ -2988,7 +2988,7 @@ Shader LoadShader(const char *vsFileName, const char *fsFileName)
 Shader LoadShaderCode(char *vsCode, char *fsCode)
 Shader LoadShaderCode(char *vsCode, char *fsCode)
 {
 {
     Shader shader = { 0 };
     Shader shader = { 0 };
-    shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS*sizeof(int), 1);
+    shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS, sizeof(int));
 
 
     // NOTE: All locations must be reseted to -1 (no location)
     // NOTE: All locations must be reseted to -1 (no location)
     for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1;
     for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1;
@@ -3861,7 +3861,7 @@ static unsigned int LoadShaderProgram(unsigned int vShaderId, unsigned int fShad
 static Shader LoadShaderDefault(void)
 static Shader LoadShaderDefault(void)
 {
 {
     Shader shader = { 0 };
     Shader shader = { 0 };
-    shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS*sizeof(int), 1);
+    shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS, sizeof(int));
 
 
     // NOTE: All locations must be reseted to -1 (no location)
     // NOTE: All locations must be reseted to -1 (no location)
     for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1;
     for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1;