@@ -889,7 +889,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
889889 #endif
890890#endif
891891
892- #include <stdlib.h> // Required for: malloc (), free()
892+ #include <stdlib.h> // Required for: calloc (), free()
893893#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
894894#include <math.h> // Required for: sqrtf(), sinf(), cosf(), floor(), log()
895895
@@ -2429,7 +2429,7 @@ void rlLoadExtensions(void *loader)
24292429
24302430 // Get supported extensions list
24312431 GLint numExt = 0 ;
2432- const char * * extList = (const char * * )RL_MALLOC (512 * sizeof (const char * )); // Allocate 512 strings pointers (2 KB)
2432+ const char * * extList = (const char * * )RL_CALLOC (512 , sizeof (const char * )); // Allocate 512 strings pointers (2 KB)
24332433 const char * extensions = (const char * )glGetString (GL_EXTENSIONS ); // One big const string
24342434
24352435 // NOTE: We have to duplicate string because glGetString() returns a const string
@@ -2741,21 +2741,21 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
27412741#if defined(GRAPHICS_API_OPENGL_33 ) || defined(GRAPHICS_API_OPENGL_ES2 )
27422742 // Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)
27432743 //--------------------------------------------------------------------------------------------
2744- batch .vertexBuffer = (rlVertexBuffer * )RL_MALLOC (numBuffers * sizeof (rlVertexBuffer ));
2744+ batch .vertexBuffer = (rlVertexBuffer * )RL_CALLOC (numBuffers , sizeof (rlVertexBuffer ));
27452745
27462746 for (int i = 0 ; i < numBuffers ; i ++ )
27472747 {
27482748 batch .vertexBuffer [i ].elementCount = bufferElements ;
27492749
2750- batch .vertexBuffer [i ].vertices = (float * )RL_MALLOC (bufferElements * 3 * 4 * sizeof (float )); // 3 float by vertex, 4 vertex by quad
2751- batch .vertexBuffer [i ].texcoords = (float * )RL_MALLOC (bufferElements * 2 * 4 * sizeof (float )); // 2 float by texcoord, 4 texcoord by quad
2752- batch .vertexBuffer [i ].normals = (float * )RL_MALLOC (bufferElements * 3 * 4 * sizeof (float )); // 3 float by vertex, 4 vertex by quad
2753- batch .vertexBuffer [i ].colors = (unsigned char * )RL_MALLOC (bufferElements * 4 * 4 * sizeof (unsigned char )); // 4 float by color, 4 colors by quad
2750+ batch .vertexBuffer [i ].vertices = (float * )RL_CALLOC (bufferElements * 3 * 4 , sizeof (float )); // 3 float by vertex, 4 vertex by quad
2751+ batch .vertexBuffer [i ].texcoords = (float * )RL_CALLOC (bufferElements * 2 * 4 , sizeof (float )); // 2 float by texcoord, 4 texcoord by quad
2752+ batch .vertexBuffer [i ].normals = (float * )RL_CALLOC (bufferElements * 3 * 4 , sizeof (float )); // 3 float by vertex, 4 vertex by quad
2753+ batch .vertexBuffer [i ].colors = (unsigned char * )RL_CALLOC (bufferElements * 4 * 4 , sizeof (unsigned char )); // 4 float by color, 4 colors by quad
27542754#if defined(GRAPHICS_API_OPENGL_33 )
2755- batch .vertexBuffer [i ].indices = (unsigned int * )RL_MALLOC (bufferElements * 6 * sizeof (unsigned int )); // 6 int by quad (indices)
2755+ batch .vertexBuffer [i ].indices = (unsigned int * )RL_CALLOC (bufferElements * 6 , sizeof (unsigned int )); // 6 int by quad (indices)
27562756#endif
27572757#if defined(GRAPHICS_API_OPENGL_ES2 )
2758- batch .vertexBuffer [i ].indices = (unsigned short * )RL_MALLOC (bufferElements * 6 * sizeof (unsigned short )); // 6 int by quad (indices)
2758+ batch .vertexBuffer [i ].indices = (unsigned short * )RL_CALLOC (bufferElements * 6 , sizeof (unsigned short )); // 6 int by quad (indices)
27592759#endif
27602760
27612761 for (int j = 0 ; j < (3 * 4 * bufferElements ); j ++ ) batch .vertexBuffer [i ].vertices [j ] = 0.0f ;
@@ -2843,7 +2843,7 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
28432843
28442844 // Init draw calls tracking system
28452845 //--------------------------------------------------------------------------------------------
2846- batch .draws = (rlDrawCall * )RL_MALLOC (RL_DEFAULT_BATCH_DRAWCALLS * sizeof (rlDrawCall ));
2846+ batch .draws = (rlDrawCall * )RL_CALLOC (RL_DEFAULT_BATCH_DRAWCALLS , sizeof (rlDrawCall ));
28472847
28482848 for (int i = 0 ; i < RL_DEFAULT_BATCH_DRAWCALLS ; i ++ )
28492849 {
@@ -3649,7 +3649,7 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
36493649
36503650 if ((glInternalFormat != 0 ) && (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB ))
36513651 {
3652- pixels = RL_MALLOC (size );
3652+ pixels = RL_CALLOC (size , 1 );
36533653 glGetTexImage (GL_TEXTURE_2D , 0 , glFormat , glType , pixels );
36543654 }
36553655 else TRACELOG (RL_LOG_WARNING , "TEXTURE: [ID %i] Data retrieval not suported for pixel format (%i)" , id , format );
@@ -3674,7 +3674,7 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
36743674 glFramebufferTexture2D (GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , id , 0 );
36753675
36763676 // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
3677- pixels = ( unsigned char * ) RL_MALLOC ( rlGetPixelDataSize (width , height , RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 ));
3677+ pixels = RL_CALLOC ( rlGetPixelDataSize (width , height , RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 ), 1 );
36783678 glReadPixels (0 , 0 , width , height , GL_RGBA , GL_UNSIGNED_BYTE , pixels );
36793679
36803680 glBindFramebuffer (GL_FRAMEBUFFER , 0 );
0 commit comments