12 Commits

Author SHA1 Message Date
Ray
0dedaf3066 Update rmodels.c 2026-11-10 09:11:30 +01:00
Ray
6522f2746e Update raudio.c 2026-11-10 09:11:24 +01:00
Ray
3d93734128 Update shapes_penrose_tile.c 2026-11-10 08:31:08 +01:00
Ray
d26ba945ec Update rshapes.c 2026-11-10 08:29:17 +01:00
Ray
51d2c126e1 Update shapes_clock_of_clocks.c 2026-11-10 08:25:38 +01:00
Ray
5bc8db53bc Use RL_CALLOC for memory allocations everywhere 2026-11-10 08:22:20 +01:00
Ray
f59bbedd8d Update CONVENTIONS.md 2026-11-10 08:03:43 +01:00
6fd4082e1e [rcore] Fix DecodeDataBase64() reading before the input on empty or padding-only strings (#6339) 2026-11-10 07:53:06 +01:00
Ray
8d8d8c3e7b REVIEWED: RestoreWindow(), fixes #6397 2026-11-10 07:33:38 +01:00
Ray
c4cebe60e4 Update rcore.c 2026-11-10 07:28:27 +01:00
3ade99817a [rcore] Fix FileCopy() and FileMove() reporting success when the copy failed (#6364)
* [rcore] Fix `FileCopy()` and `FileMove()` reporting success when the copy failed

Since #5920, `FileCopy()` sets `result` to 0 once the destination
directory exists and never resets it, so it returns 0 when the source
is missing or empty or when the destination can't be written.

`FileMove()` trusts that result. If the destination is an existing file
of the same size that can't be overwritten (e.g. read-only), the length
check passes and the source file is removed although nothing was copied.

Only return 0 from `FileCopy()` when the data was saved, and make
`FileMove()` return -1 when the copied file does not check out.

* FileMove: drop the extra failure result, FileCopy already reports it
2026-11-10 07:22:29 +01:00
Ray
f2c8c11bdc Fix automations events potential out-of-bounds 2026-11-10 07:21:11 +01:00
10 changed files with 148 additions and 165 deletions

View File

@ -77,6 +77,7 @@ if (dataPtr != NULL)
dataPtr = NULL;
}
```
- Memory allocation return value checks: no checks are done, the probabilities of allocators failing are very low and it would add a great amount of checking code, if a finer control is needed for allocators, macors can be overriden by custom implementations.
**If proposing new functions, please try to use a clear naming for function-name and functions-parameters, in case of doubt, open an issue for discussion.**

View File

@ -150,7 +150,7 @@ int main(void)
float xOffset = 4.0f;
for (int digit = 0; digit < 6; digit++)
for (unsigned int digit = 0; digit < 6; digit++)
{
for (int row = 0; row < 6; row++)
{
@ -165,7 +165,7 @@ int main(void)
// Big hand
DrawRectanglePro(
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f+4.0f, 4.0f},
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f + 4.0f, 4.0f},
(Vector2){ 2.0f, 2.0f },
currentAngles[digit][row*4+col].x,
handsColor
@ -173,16 +173,16 @@ int main(void)
// Little hand
DrawRectanglePro(
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f+2.0f, 4.0f},
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f + 2.0f, 4.0f},
(Vector2){ 2.0f, 2.0f },
currentAngles[digit][row*4+col].y,
currentAngles[digit][row*4 + col].y,
handsColor
);
}
}
xOffset += (clockFaceSize+clockFaceSpacing)*4;
if (digit%2 == 1)
if ((digit%2) == 1)
{
DrawRing((Vector2){xOffset + 4.0f, 160.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
DrawRing((Vector2){xOffset + 4.0f, 225.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);

View File

@ -76,7 +76,7 @@ int main(void)
float drawLength = 460.0f;
int minGenerations = 0;
int maxGenerations = 4;
int generations = 0;
int generations = 1;
// Initialize new penrose tile
PenroseLSystem ls = LoadPenroseLSystem(drawLength*(generations/(float)maxGenerations));

View File

@ -359,7 +359,8 @@ void MinimizeWindow(void)
// Restore window from being minimized/maximized
void RestoreWindow(void)
{
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
if ((glfwGetWindowAttrib(platform.handle, GLFW_ICONIFIED) == GLFW_TRUE) ||
(glfwGetWindowAttrib(platform.handle, GLFW_MAXIMIZED) == GLFW_TRUE))
{
// Restores the specified window if it was previously iconified (minimized) or maximized
glfwRestoreWindow(platform.handle);

View File

@ -576,7 +576,7 @@ static void RGFW_cb_windowresizefunc(const RGFW_event *e)
if (platform.surfacePixels != NULL)
{
RL_FREE(platform.surfacePixels);
platform.surfacePixels = RL_MALLOC(platform.surfaceWidth*platform.surfaceHeight*4);
platform.surfacePixels = RL_CALLOC(platform.surfaceWidth*platform.surfaceHeight*4, 1);
}
if (platform.surface != NULL)
@ -1887,13 +1887,7 @@ int InitPlatform(void)
platform.surfaceWidth = CORE.Window.currentFbo.width;
platform.surfaceHeight = CORE.Window.currentFbo.height;
platform.surfacePixels = RL_MALLOC(platform.surfaceWidth*platform.surfaceHeight*4);
if (platform.surfacePixels == NULL)
{
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize software pixel buffer");
return -1;
}
platform.surfacePixels = RL_CALLOC(platform.surfaceWidth*platform.surfaceHeight*4, 1);
platform.surface = RGFW_window_createSurface(platform.window, platform.surfacePixels, platform.surfaceWidth, platform.surfaceHeight, RGFW_formatBGRA8);

View File

@ -1396,7 +1396,7 @@ const char *GetClipboardText(void)
int length = (int)wcsnlen(clipboardText, maxLength);
int size = WideCharToMultiByte(CP_UTF8, 0, clipboardText, length, NULL, 0, NULL, NULL);
char *utf8Text = (char *)RL_MALLOC(size + 1);
char *utf8Text = (char *)RL_CALLOC(size + 1, 1);
if ((size > 0) && (WideCharToMultiByte(CP_UTF8, 0, clipboardText, length, utf8Text, size, NULL, NULL) == 0)) size = 0;
utf8Text[size] = '\0';

View File

@ -1086,11 +1086,11 @@ bool ExportWave(Wave wave, const char *fileName)
void *fileData = NULL;
size_t fileDataSize = 0;
result = drwav_init_memory_write(&wav, &fileData, &fileDataSize, &format, NULL);
if (result) result = (int)drwav_write_pcm_frames(&wav, wave.frameCount, wave.data);
drwav_result result = drwav_uninit(&wav);
drwav_init_memory_write(&wav, &fileData, &fileDataSize, &format, NULL);
drwav_write_pcm_frames(&wav, wave.frameCount, wave.data);
drwav_uninit(&wav);
if (result == DRWAV_SUCCESS) result = SaveFileData(fileName, (unsigned char *)fileData, (unsigned int)fileDataSize);
result = SaveFileData(fileName, (unsigned char *)fileData, (unsigned int)fileDataSize);
drwav_free(fileData, NULL);
}

View File

@ -448,8 +448,10 @@ typedef enum AutomationEventType {
ACTION_SETTARGETFPS // param[0]: fps
} AutomationEventType;
#define MAX_AUTOMATION_EVENT_TYPES 24
// Event type name strings, required for export
static const char *autoEventTypeName[] = {
static const char *autoEventTypeName[MAX_AUTOMATION_EVENT_TYPES] = {
"EVENT_NONE",
"INPUT_KEY_UP",
"INPUT_KEY_DOWN",
@ -2246,16 +2248,16 @@ int FileCopy(const char *srcPath, const char *dstPath)
int srcDataSize = 0;
unsigned char *srcFileData = LoadFileData(srcPath, &srcDataSize);
// Create required paths if they do not exist
if (DirectoryExists(GetDirectoryPath(dstPath))) result = 0; // Already exists
else result = MakeDirectory(GetDirectoryPath(dstPath));
if (result == 0) // Directory created successfully or already exists
if ((srcFileData != NULL) && (srcDataSize > 0))
{
if ((srcFileData != NULL) && (srcDataSize > 0))
// Get full destination directory path
const char *dstDirPath = GetDirectoryPath(dstPath);
// Check if directory exist or create it otherwise
if (DirectoryExists(dstDirPath) || (MakeDirectory(dstDirPath) == 0))
{
bool saved = SaveFileData(dstPath, srcFileData, srcDataSize);
if (saved) result = 0;
if (saved) result = 0; // WARNING: SaveFileData() returns true on success
}
}
@ -3200,8 +3202,9 @@ unsigned char *DecodeDataBase64(const char *text, int *outputSize)
int dataSize = (int)strlen(text); // WARNING: Expecting NULL terminated strings!
int ending = dataSize - 1;
int padding = 0;
while (text[ending] == '=') { padding++; ending--; }
while ((ending >= 0) && (text[ending] == '=')) { padding++; ending--; }
int estimatedOutputSize = 3*(dataSize/4) - padding;
if (estimatedOutputSize < 0) estimatedOutputSize = 0; // Invalid input, i.e. "QQ=" or "===="
int maxOutputSize = 3*(dataSize/4);
// Load some memory to store decoded data
@ -3767,6 +3770,8 @@ bool ExportAutomationEventList(AutomationEventList list, const char *fileName)
byteCount += sprintf(txtData + byteCount, "c %i\n", list.count);
for (unsigned int i = 0; i < list.count; i++)
{
if ((list.events[i].type < 0) || (list.events[i].type >= MAX_AUTOMATION_EVENT_TYPES)) list.events[i].type = 0;
byteCount += snprintf(txtData + byteCount, 256, "e %i %i %i %i %i %i // Event: %s\n", list.events[i].frame, list.events[i].type,
list.events[i].params[0], list.events[i].params[1], list.events[i].params[2], list.events[i].params[3], autoEventTypeName[list.events[i].type]);
}

View File

@ -2640,7 +2640,7 @@ Mesh GenMeshPoly(int sides, float radius)
int vertexCount = sides*3;
// Vertices definition
Vector3 *vertices = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3));
Vector3 *vertices = (Vector3 *)RL_CALLOC(vertexCount, sizeof(Vector3));
float d = 0.0f, dStep = 360.0f/sides;
for (int v = 0; v < vertexCount - 2; v += 3)
@ -2652,18 +2652,18 @@ Mesh GenMeshPoly(int sides, float radius)
}
// Normals definition
Vector3 *normals = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3));
Vector3 *normals = (Vector3 *)RL_CALLOC(vertexCount, sizeof(Vector3));
for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up;
// TexCoords definition
Vector2 *texcoords = (Vector2 *)RL_MALLOC(vertexCount*sizeof(Vector2));
Vector2 *texcoords = (Vector2 *)RL_CALLOC(vertexCount, sizeof(Vector2));
for (int n = 0; n < vertexCount; n++) texcoords[n] = (Vector2){ 0.0f, 0.0f };
mesh.vertexCount = vertexCount;
mesh.triangleCount = sides;
mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
// Mesh vertices position array
for (int i = 0; i < mesh.vertexCount; i++)
@ -2712,7 +2712,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
// Vertices definition
int vertexCount = resX*resZ; // vertices get reused for the faces
Vector3 *vertices = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3));
Vector3 *vertices = (Vector3 *)RL_CALLOC(vertexCount, sizeof(Vector3));
for (int z = 0; z < resZ; z++)
{
// [-length/2, length/2]
@ -2726,11 +2726,11 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
}
// Normals definition
Vector3 *normals = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3));
Vector3 *normals = (Vector3 *)RL_CALLOC(vertexCount, sizeof(Vector3));
for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up;
// TexCoords definition
Vector2 *texcoords = (Vector2 *)RL_MALLOC(vertexCount*sizeof(Vector2));
Vector2 *texcoords = (Vector2 *)RL_CALLOC(vertexCount, sizeof(Vector2));
for (int v = 0; v < resZ; v++)
{
for (int u = 0; u < resX; u++)
@ -2741,7 +2741,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
// Triangles definition (indices)
int numFaces = (resX - 1)*(resZ - 1);
int *triangles = (int *)RL_MALLOC(numFaces*6*sizeof(int));
int *triangles = (int *)RL_CALLOC(numFaces*6, sizeof(int));
int t = 0;
for (int face = 0; face < numFaces; face++)
{
@ -2759,10 +2759,10 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
mesh.vertexCount = vertexCount;
mesh.triangleCount = numFaces*2;
mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
mesh.indices = (unsigned short *)RL_MALLOC(mesh.triangleCount*3*sizeof(unsigned short));
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
mesh.indices = (unsigned short *)RL_CALLOC(mesh.triangleCount*3, sizeof(unsigned short));
// Mesh vertices position array
for (int i = 0; i < mesh.vertexCount; i++)
@ -2802,9 +2802,9 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
par_shapes_rotate(plane, -PI/2.0f, (float[]){ 1, 0, 0 });
par_shapes_translate(plane, -width/2, 0.0f, length/2);
mesh.vertices = (float *)RL_MALLOC(plane->ntriangles*3*3*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.vertices = (float *)RL_CALLOC(plane->ntriangles*3*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(plane->ntriangles*3*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(plane->ntriangles*3*3, sizeof(float));
mesh.vertexCount = plane->ntriangles*3;
mesh.triangleCount = plane->ntriangles;
@ -2920,16 +2920,16 @@ Mesh GenMeshCube(float width, float height, float length)
-1.0f, 0.0f, 0.0f
};
mesh.vertices = (float *)RL_MALLOC(24*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(24*3, sizeof(float));
memcpy(mesh.vertices, vertices, 24*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(24*2*sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(24*2, sizeof(float));
memcpy(mesh.texcoords, texcoords, 24*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(24*3*sizeof(float));
mesh.normals = (float *)RL_CALLOC(24*3, sizeof(float));
memcpy(mesh.normals, normals, 24*3*sizeof(float));
mesh.indices = (unsigned short *)RL_MALLOC(36*sizeof(unsigned short));
mesh.indices = (unsigned short *)RL_CALLOC(36, sizeof(unsigned short));
int k = 0;
@ -2967,9 +2967,9 @@ par_shapes_mesh *par_shapes_create_icosahedron(); // 20 sides polyhedron
par_shapes_translate(cube, -width/2, 0.0f, -length/2);
par_shapes_compute_normals(cube);
mesh.vertices = (float *)RL_MALLOC(cube->ntriangles*3*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(cube->ntriangles*3*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(cube->ntriangles*3*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(cube->ntriangles*3*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(cube->ntriangles*3*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(cube->ntriangles*3*3, sizeof(float));
mesh.vertexCount = cube->ntriangles*3;
mesh.triangleCount = cube->ntriangles;
@ -3009,9 +3009,9 @@ Mesh GenMeshSphere(float radius, int rings, int slices)
par_shapes_scale(sphere, radius, radius, radius);
// NOTE: Soft normals are computed internally
mesh.vertices = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(sphere->ntriangles*3*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(sphere->ntriangles*3*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(sphere->ntriangles*3*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(sphere->ntriangles*3*3, sizeof(float));
mesh.vertexCount = sphere->ntriangles*3;
mesh.triangleCount = sphere->ntriangles;
@ -3053,9 +3053,9 @@ Mesh GenMeshHemiSphere(float radius, int rings, int slices)
par_shapes_scale(sphere, radius, radius, radius);
// NOTE: Soft normals are computed internally
mesh.vertices = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(sphere->ntriangles*3*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(sphere->ntriangles*3*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(sphere->ntriangles*3*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(sphere->ntriangles*3*3, sizeof(float));
mesh.vertexCount = sphere->ntriangles*3;
mesh.triangleCount = sphere->ntriangles;
@ -3117,9 +3117,9 @@ Mesh GenMeshCylinder(float radius, float height, int slices)
par_shapes_merge_and_free(cylinder, capTop);
par_shapes_merge_and_free(cylinder, capBottom);
mesh.vertices = (float *)RL_MALLOC(cylinder->ntriangles*3*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(cylinder->ntriangles*3*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(cylinder->ntriangles*3*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(cylinder->ntriangles*3*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(cylinder->ntriangles*3*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(cylinder->ntriangles*3*3, sizeof(float));
mesh.vertexCount = cylinder->ntriangles*3;
mesh.triangleCount = cylinder->ntriangles;
@ -3172,9 +3172,9 @@ Mesh GenMeshCone(float radius, float height, int slices)
par_shapes_merge_and_free(cone, capBottom);
mesh.vertices = (float *)RL_MALLOC(cone->ntriangles*3*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(cone->ntriangles*3*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(cone->ntriangles*3*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(cone->ntriangles*3*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(cone->ntriangles*3*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(cone->ntriangles*3*3, sizeof(float));
mesh.vertexCount = cone->ntriangles*3;
mesh.triangleCount = cone->ntriangles;
@ -3220,9 +3220,9 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
par_shapes_mesh *torus = par_shapes_create_torus(radSeg, sides, radius);
par_shapes_scale(torus, size/2, size/2, size/2);
mesh.vertices = (float *)RL_MALLOC(torus->ntriangles*3*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(torus->ntriangles*3*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(torus->ntriangles*3*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(torus->ntriangles*3*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(torus->ntriangles*3*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(torus->ntriangles*3*3, sizeof(float));
mesh.vertexCount = torus->ntriangles*3;
mesh.triangleCount = torus->ntriangles;
@ -3264,9 +3264,9 @@ Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
par_shapes_mesh *knot = par_shapes_create_trefoil_knot(radSeg, sides, radius);
par_shapes_scale(knot, size, size, size);
mesh.vertices = (float *)RL_MALLOC(knot->ntriangles*3*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(knot->ntriangles*3*2*sizeof(float));
mesh.normals = (float *)RL_MALLOC(knot->ntriangles*3*3*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(knot->ntriangles*3*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(knot->ntriangles*3*2, sizeof(float));
mesh.normals = (float *)RL_CALLOC(knot->ntriangles*3*3, sizeof(float));
mesh.vertexCount = knot->ntriangles*3;
mesh.triangleCount = knot->ntriangles;
@ -3313,9 +3313,9 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
mesh.vertexCount = mesh.triangleCount*3;
mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
mesh.colors = NULL;
int vCounter = 0; // Used to count vertices float by float
@ -3448,9 +3448,9 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
float h = cubeSize.z;
float h2 = cubeSize.y;
Vector3 *mapVertices = (Vector3 *)RL_MALLOC(maxTriangles*3*sizeof(Vector3));
Vector2 *mapTexcoords = (Vector2 *)RL_MALLOC(maxTriangles*3*sizeof(Vector2));
Vector3 *mapNormals = (Vector3 *)RL_MALLOC(maxTriangles*3*sizeof(Vector3));
Vector3 *mapVertices = (Vector3 *)RL_CALLOC(maxTriangles*3, sizeof(Vector3));
Vector2 *mapTexcoords = (Vector2 *)RL_CALLOC(maxTriangles*3, sizeof(Vector2));
Vector3 *mapNormals = (Vector3 *)RL_CALLOC(maxTriangles*3, sizeof(Vector3));
// Define the 6 normals of the cube, combined accordingly later
Vector3 n1 = { 1.0f, 0.0f, 0.0f };
@ -3727,9 +3727,9 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
mesh.vertexCount = vCounter;
mesh.triangleCount = vCounter/3;
mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
mesh.colors = NULL;
int fCounter = 0;
@ -3816,11 +3816,11 @@ void GenMeshTangents(Mesh *mesh)
}
// Allocate or reallocate tangents data
if (mesh->tangents == NULL) mesh->tangents = (float *)RL_MALLOC(mesh->vertexCount*4*sizeof(float));
if (mesh->tangents == NULL) mesh->tangents = (float *)RL_CALLOC(mesh->vertexCount*4, sizeof(float));
else
{
RL_FREE(mesh->tangents);
mesh->tangents = (float *)RL_MALLOC(mesh->vertexCount*4*sizeof(float));
mesh->tangents = (float *)RL_CALLOC(mesh->vertexCount*4, sizeof(float));
}
// Allocate temporary arrays for tangents calculation
@ -4874,7 +4874,7 @@ static Model LoadIQM(const char *fileName)
//fileDataPtr += sizeof(IQMHeader); // Move file data pointer
// Meshes data processing
imesh = (IQMMesh *)RL_MALLOC(iqmHeader->num_meshes*sizeof(IQMMesh));
imesh = (IQMMesh *)RL_CALLOC(iqmHeader->num_meshes, sizeof(IQMMesh));
//fseek(iqmFile, iqmHeader->ofs_meshes, SEEK_SET);
//fread(imesh, sizeof(IQMMesh)*iqmHeader->num_meshes, 1, iqmFile);
memcpy(imesh, fileDataPtr + iqmHeader->ofs_meshes, iqmHeader->num_meshes*sizeof(IQMMesh));
@ -4920,7 +4920,7 @@ static Model LoadIQM(const char *fileName)
}
// Triangles data processing
tri = (IQMTriangle *)RL_MALLOC(iqmHeader->num_triangles*sizeof(IQMTriangle));
tri = (IQMTriangle *)RL_CALLOC(iqmHeader->num_triangles, sizeof(IQMTriangle));
//fseek(iqmFile, iqmHeader->ofs_triangles, SEEK_SET);
//fread(tri, sizeof(IQMTriangle), iqmHeader->num_triangles, iqmFile);
memcpy(tri, fileDataPtr + iqmHeader->ofs_triangles, iqmHeader->num_triangles*sizeof(IQMTriangle));
@ -4942,7 +4942,7 @@ static Model LoadIQM(const char *fileName)
}
// Vertex arrays data processing
va = (IQMVertexArray *)RL_MALLOC(iqmHeader->num_vertexarrays*sizeof(IQMVertexArray));
va = (IQMVertexArray *)RL_CALLOC(iqmHeader->num_vertexarrays, sizeof(IQMVertexArray));
//fseek(iqmFile, iqmHeader->ofs_vertexarrays, SEEK_SET);
//fread(va, sizeof(IQMVertexArray), iqmHeader->num_vertexarrays, iqmFile);
memcpy(va, fileDataPtr + iqmHeader->ofs_vertexarrays, iqmHeader->num_vertexarrays*sizeof(IQMVertexArray));
@ -4953,7 +4953,7 @@ static Model LoadIQM(const char *fileName)
{
case IQM_POSITION:
{
vertex = (float *)RL_MALLOC(iqmHeader->num_vertexes*3*sizeof(float));
vertex = (float *)RL_CALLOC(iqmHeader->num_vertexes*3, sizeof(float));
//fseek(iqmFile, va[a].offset, SEEK_SET);
//fread(vertex, iqmHeader->num_vertexes*3*sizeof(float), 1, iqmFile);
memcpy(vertex, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*3*sizeof(float));
@ -4971,7 +4971,7 @@ static Model LoadIQM(const char *fileName)
} break;
case IQM_NORMAL:
{
normal = (float *)RL_MALLOC(iqmHeader->num_vertexes*3*sizeof(float));
normal = (float *)RL_CALLOC(iqmHeader->num_vertexes*3, sizeof(float));
//fseek(iqmFile, va[a].offset, SEEK_SET);
//fread(normal, iqmHeader->num_vertexes*3*sizeof(float), 1, iqmFile);
memcpy(normal, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*3*sizeof(float));
@ -4989,7 +4989,7 @@ static Model LoadIQM(const char *fileName)
} break;
case IQM_TEXCOORD:
{
text = (float *)RL_MALLOC(iqmHeader->num_vertexes*2*sizeof(float));
text = (float *)RL_CALLOC(iqmHeader->num_vertexes*2, sizeof(float));
//fseek(iqmFile, va[a].offset, SEEK_SET);
//fread(text, iqmHeader->num_vertexes*2*sizeof(float), 1, iqmFile);
memcpy(text, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*2*sizeof(float));
@ -5006,7 +5006,7 @@ static Model LoadIQM(const char *fileName)
} break;
case IQM_BLENDINDEXES:
{
blendi = (char *)RL_MALLOC(iqmHeader->num_vertexes*4*sizeof(char));
blendi = (char *)RL_CALLOC(iqmHeader->num_vertexes*4, sizeof(char));
//fseek(iqmFile, va[a].offset, SEEK_SET);
//fread(blendi, iqmHeader->num_vertexes*4*sizeof(char), 1, iqmFile);
memcpy(blendi, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(char));
@ -5023,7 +5023,7 @@ static Model LoadIQM(const char *fileName)
} break;
case IQM_BLENDWEIGHTS:
{
blendw = (unsigned char *)RL_MALLOC(iqmHeader->num_vertexes*4*sizeof(unsigned char));
blendw = (unsigned char *)RL_CALLOC(iqmHeader->num_vertexes*4, sizeof(unsigned char));
//fseek(iqmFile, va[a].offset, SEEK_SET);
//fread(blendw, iqmHeader->num_vertexes*4*sizeof(unsigned char), 1, iqmFile);
memcpy(blendw, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(unsigned char));
@ -5040,7 +5040,7 @@ static Model LoadIQM(const char *fileName)
} break;
case IQM_COLOR:
{
color = (unsigned char *)RL_MALLOC(iqmHeader->num_vertexes*4*sizeof(unsigned char));
color = (unsigned char *)RL_CALLOC(iqmHeader->num_vertexes*4, sizeof(unsigned char));
//fseek(iqmFile, va[a].offset, SEEK_SET);
//fread(blendw, iqmHeader->num_vertexes*4*sizeof(unsigned char), 1, iqmFile);
memcpy(color, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(unsigned char));
@ -5061,7 +5061,7 @@ static Model LoadIQM(const char *fileName)
}
// Bones (joints) data processing
ijoint = (IQMJoint *)RL_MALLOC(iqmHeader->num_joints*sizeof(IQMJoint));
ijoint = (IQMJoint *)RL_CALLOC(iqmHeader->num_joints, sizeof(IQMJoint));
//fseek(iqmFile, iqmHeader->ofs_joints, SEEK_SET);
//fread(ijoint, sizeof(IQMJoint), iqmHeader->num_joints, iqmFile);
memcpy(ijoint, fileDataPtr + iqmHeader->ofs_joints, iqmHeader->num_joints*sizeof(IQMJoint));
@ -5184,14 +5184,14 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, int *animCou
}
// Get bones data
IQMPose *poses = (IQMPose *)RL_MALLOC(iqmHeader->num_poses*sizeof(IQMPose));
IQMPose *poses = (IQMPose *)RL_CALLOC(iqmHeader->num_poses, sizeof(IQMPose));
//fseek(iqmFile, iqmHeader->ofs_poses, SEEK_SET);
//fread(poses, sizeof(IQMPose), iqmHeader->num_poses, iqmFile);
memcpy(poses, fileDataPtr + iqmHeader->ofs_poses, iqmHeader->num_poses*sizeof(IQMPose));
// Get animations data
*animCount = iqmHeader->num_anims;
IQMAnim *anim = (IQMAnim *)RL_MALLOC(iqmHeader->num_anims*sizeof(IQMAnim));
IQMAnim *anim = (IQMAnim *)RL_CALLOC(iqmHeader->num_anims, sizeof(IQMAnim));
//fseek(iqmFile, iqmHeader->ofs_anims, SEEK_SET);
//fread(anim, sizeof(IQMAnim), iqmHeader->num_anims, iqmFile);
memcpy(anim, fileDataPtr + iqmHeader->ofs_anims, iqmHeader->num_anims*sizeof(IQMAnim));
@ -5231,7 +5231,7 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, int *animCou
}
for (unsigned int j = 0; j < anim[a].num_frames; j++)
animations[a].keyframePoses[j] = (Transform *)RL_MALLOC(iqmHeader->num_poses*sizeof(Transform));
animations[a].keyframePoses[j] = (Transform *)RL_CALLOC(iqmHeader->num_poses, sizeof(Transform));
int dcounter = anim[a].first_frame*iqmHeader->num_framechannels;
@ -5424,7 +5424,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
}
else if ((cgltfImage->buffer_view != NULL) && (cgltfImage->buffer_view->buffer->data != NULL)) // Check if image is provided as data buffer
{
unsigned char *data = (unsigned char *)RL_MALLOC(cgltfImage->buffer_view->size);
unsigned char *data = (unsigned char *)RL_CALLOC(cgltfImage->buffer_view->size, sizeof(unsigned char));
int offset = (int)cgltfImage->buffer_view->offset;
int stride = (int)cgltfImage->buffer_view->stride? (int)cgltfImage->buffer_view->stride : 1;
@ -5647,8 +5647,8 @@ static Model LoadGLTF(const char *fileName)
Image imMetallic = { 0 };
Image imRoughness = { 0 };
imMetallic.data = RL_MALLOC(imMetallicRoughness.width*imMetallicRoughness.height);
imRoughness.data = RL_MALLOC(imMetallicRoughness.width*imMetallicRoughness.height);
imMetallic.data = RL_CALLOC(imMetallicRoughness.width*imMetallicRoughness.height, 1);
imRoughness.data = RL_CALLOC(imMetallicRoughness.width*imMetallicRoughness.height, 1);
imMetallic.width = imRoughness.width = imMetallicRoughness.width;
imMetallic.height = imRoughness.height = imMetallicRoughness.height;
@ -5782,7 +5782,7 @@ static Model LoadGLTF(const char *fileName)
{
// Init raylib mesh vertices to copy glTF attribute data
model.meshes[meshIndex].vertexCount = (int)attribute->count;
model.meshes[meshIndex].vertices = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
model.meshes[meshIndex].vertices = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
// Load 3 components of float data type into mesh.vertices
LOAD_ATTRIBUTE(attribute, 3, float, model.meshes[meshIndex].vertices)
@ -5801,10 +5801,10 @@ static Model LoadGLTF(const char *fileName)
{
// Init raylib mesh vertices to copy glTF attribute data
model.meshes[meshIndex].vertexCount = (int)attribute->count;
model.meshes[meshIndex].vertices = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
model.meshes[meshIndex].vertices = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*3*sizeof(unsigned short));
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*3, sizeof(unsigned short));
LOAD_ATTRIBUTE(attribute, 3, unsigned short, temp);
// Convert data to raylib vertex data type (float) the matrix will scale it to the correct size as a float
@ -5826,10 +5826,10 @@ static Model LoadGLTF(const char *fileName)
{
// Init raylib mesh vertices to copy glTF attribute data
model.meshes[meshIndex].vertexCount = (int)attribute->count;
model.meshes[meshIndex].vertices = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
model.meshes[meshIndex].vertices = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
short *temp = (short *)RL_MALLOC(attribute->count*3*sizeof(short));
short *temp = (short *)RL_CALLOC(attribute->count*3, sizeof(short));
LOAD_ATTRIBUTE(attribute, 3, short, temp);
// Convert data to raylib vertex data type (float) the matrix will scale it to the correct size as a float
@ -5860,7 +5860,7 @@ static Model LoadGLTF(const char *fileName)
if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_32f))
{
// Init raylib mesh normals to copy glTF attribute data
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
model.meshes[meshIndex].normals = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
// Load 3 components of float data type into mesh.normals
LOAD_ATTRIBUTE(attribute, 3, float, model.meshes[meshIndex].normals)
@ -5878,10 +5878,10 @@ static Model LoadGLTF(const char *fileName)
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_16))
{
// Init raylib mesh normals to copy glTF attribute data
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
model.meshes[meshIndex].normals = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
short *temp = (short *)RL_MALLOC(attribute->count*3*sizeof(short));
short *temp = (short *)RL_CALLOC(attribute->count*3, sizeof(short));
LOAD_ATTRIBUTE(attribute, 3, short, temp);
// Convert data to raylib normal data type (float)
@ -5902,10 +5902,10 @@ static Model LoadGLTF(const char *fileName)
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_8u))
{
// Init raylib mesh normals to copy glTF attribute data
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
model.meshes[meshIndex].normals = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*3*sizeof(unsigned char));
unsigned char *temp = (unsigned char *)RL_CALLOC(attribute->count*3, sizeof(unsigned char));
LOAD_ATTRIBUTE(attribute, 3, unsigned char, temp);
// Convert data to raylib normal data type (float)
@ -5926,10 +5926,10 @@ static Model LoadGLTF(const char *fileName)
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_8))
{
// Init raylib mesh normals to copy glTF attribute data
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
model.meshes[meshIndex].normals = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
char *temp = (char *)RL_MALLOC(attribute->count*3*sizeof(char));
char *temp = (char *)RL_CALLOC(attribute->count*3, sizeof(char));
LOAD_ATTRIBUTE(attribute, 3, char, temp);
// Convert data to raylib normal data type (float)
@ -5960,7 +5960,7 @@ static Model LoadGLTF(const char *fileName)
if ((attribute->type == cgltf_type_vec4) && (attribute->component_type == cgltf_component_type_r_32f))
{
// Init raylib mesh tangent to copy glTF attribute data
model.meshes[meshIndex].tangents = (float *)RL_MALLOC(attribute->count*4*sizeof(float));
model.meshes[meshIndex].tangents = (float *)RL_CALLOC(attribute->count*4, sizeof(float));
// Load 4 components of float data type into mesh.tangents
LOAD_ATTRIBUTE(attribute, 4, float, model.meshes[meshIndex].tangents)
@ -5990,7 +5990,7 @@ static Model LoadGLTF(const char *fileName)
if (attribute->component_type == cgltf_component_type_r_32f) // vec2, float
{
// Init raylib mesh texcoords to copy glTF attribute data
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
texcoordPtr = (float *)RL_CALLOC(attribute->count*2, sizeof(float));
// Load 3 components of float data type into mesh.texcoords
LOAD_ATTRIBUTE(attribute, 2, float, texcoordPtr)
@ -5998,10 +5998,10 @@ static Model LoadGLTF(const char *fileName)
else if (attribute->component_type == cgltf_component_type_r_8u) // vec2, u8n
{
// Init raylib mesh texcoords to copy glTF attribute data
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
texcoordPtr = (float *)RL_CALLOC(attribute->count*2, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*2*sizeof(unsigned char));
unsigned char *temp = (unsigned char *)RL_CALLOC(attribute->count*2, sizeof(unsigned char));
LOAD_ATTRIBUTE(attribute, 2, unsigned char, temp);
// Convert data to raylib texcoord data type (float)
@ -6012,10 +6012,10 @@ static Model LoadGLTF(const char *fileName)
else if (attribute->component_type == cgltf_component_type_r_16u) // vec2, u16n
{
// Init raylib mesh texcoords to copy glTF attribute data
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
texcoordPtr = (float *)RL_CALLOC(attribute->count*2, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*2*sizeof(unsigned short));
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*2, sizeof(unsigned short));
LOAD_ATTRIBUTE(attribute, 2, unsigned short, temp);
// Convert data to raylib texcoord data type (float)
@ -6050,10 +6050,10 @@ static Model LoadGLTF(const char *fileName)
if (attribute->component_type == cgltf_component_type_r_8u)
{
// Init raylib mesh color to copy glTF attribute data
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
// Load data into a temp buffer to be converted to raylib data type
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*3*sizeof(unsigned char));
unsigned char *temp = (unsigned char *)RL_CALLOC(attribute->count*3, sizeof(unsigned char));
LOAD_ATTRIBUTE(attribute, 3, unsigned char, temp);
// Convert data to raylib color data type (4 bytes)
@ -6070,10 +6070,10 @@ static Model LoadGLTF(const char *fileName)
else if (attribute->component_type == cgltf_component_type_r_16u)
{
// Init raylib mesh color to copy glTF attribute data
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
// Load data into a temp buffer to be converted to raylib data type
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*3*sizeof(unsigned short));
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*3, sizeof(unsigned short));
LOAD_ATTRIBUTE(attribute, 3, unsigned short, temp);
// Convert data to raylib color data type (4 bytes)
@ -6090,10 +6090,10 @@ static Model LoadGLTF(const char *fileName)
else if (attribute->component_type == cgltf_component_type_r_32f)
{
// Init raylib mesh color to copy glTF attribute data
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
// Load data into a temp buffer to be converted to raylib data type
float *temp = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
float *temp = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
LOAD_ATTRIBUTE(attribute, 3, float, temp);
// Convert data to raylib color data type (4 bytes)
@ -6114,7 +6114,7 @@ static Model LoadGLTF(const char *fileName)
if (attribute->component_type == cgltf_component_type_r_8u)
{
// Init raylib mesh color to copy glTF attribute data
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
// Load 4 components of unsigned char data type into mesh.colors
LOAD_ATTRIBUTE(attribute, 4, unsigned char, model.meshes[meshIndex].colors)
@ -6122,10 +6122,10 @@ static Model LoadGLTF(const char *fileName)
else if (attribute->component_type == cgltf_component_type_r_16u)
{
// Init raylib mesh color to copy glTF attribute data
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
// Load data into a temp buffer to be converted to raylib data type
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*4*sizeof(unsigned short));
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*4, sizeof(unsigned short));
LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp);
// Convert data to raylib color data type (4 bytes)
@ -6136,10 +6136,10 @@ static Model LoadGLTF(const char *fileName)
else if (attribute->component_type == cgltf_component_type_r_32f)
{
// Init raylib mesh color to copy glTF attribute data
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
// Load data into a temp buffer to be converted to raylib data type
float *temp = (float *)RL_MALLOC(attribute->count*4*sizeof(float));
float *temp = (float *)RL_CALLOC(attribute->count*4, sizeof(float));
LOAD_ATTRIBUTE(attribute, 4, float, temp);
// Convert data to raylib color data type (4 bytes), color data must be normalized
@ -6169,7 +6169,7 @@ static Model LoadGLTF(const char *fileName)
if (attribute->component_type == cgltf_component_type_r_16u)
{
// Init raylib mesh indices to copy glTF attribute data
model.meshes[meshIndex].indices = (unsigned short *)RL_MALLOC(attribute->count*sizeof(unsigned short));
model.meshes[meshIndex].indices = (unsigned short *)RL_CALLOC(attribute->count, sizeof(unsigned short));
// Load unsigned short data type into mesh.indices
LOAD_ATTRIBUTE(attribute, 1, unsigned short, model.meshes[meshIndex].indices)
@ -6177,14 +6177,14 @@ static Model LoadGLTF(const char *fileName)
else if (attribute->component_type == cgltf_component_type_r_8u)
{
// Init raylib mesh indices to copy glTF attribute data
model.meshes[meshIndex].indices = (unsigned short *)RL_MALLOC(attribute->count*sizeof(unsigned short));
model.meshes[meshIndex].indices = (unsigned short *)RL_CALLOC(attribute->count, sizeof(unsigned short));
LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned char, model.meshes[meshIndex].indices, unsigned short)
}
else if (attribute->component_type == cgltf_component_type_r_32u)
{
// Init raylib mesh indices to copy glTF attribute data
model.meshes[meshIndex].indices = (unsigned short *)RL_MALLOC(attribute->count*sizeof(unsigned short));
model.meshes[meshIndex].indices = (unsigned short *)RL_CALLOC(attribute->count, sizeof(unsigned short));
LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned int, model.meshes[meshIndex].indices, unsigned short);
TRACELOG(LOG_WARNING, "MODEL: [%s] Indices data converted from u32 to u16, possible loss of data", fileName);
@ -6350,7 +6350,7 @@ static Model LoadGLTF(const char *fileName)
model.meshes[meshIndex].boneWeights = (float *)RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
unsigned char *temp = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
LOAD_ATTRIBUTE(attribute, 4, unsigned char, temp);
// Convert data to raylib bone weight data type (4 bytes)
@ -6364,7 +6364,7 @@ static Model LoadGLTF(const char *fileName)
model.meshes[meshIndex].boneWeights = (float *)RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*4*sizeof(unsigned short));
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*4, sizeof(unsigned short));
LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp);
// Convert data to raylib bone weight data type
@ -6642,7 +6642,7 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
// store bone offsets on dummy parent nodes rather than on the
// joints themselves. Depends only on the skin, not the animation.
int jointCount = (int)skin.joints_count;
Matrix *extOffset = (Matrix *)RL_MALLOC(jointCount*sizeof(Matrix));
Matrix *extOffset = (Matrix *)RL_CALLOC(jointCount, sizeof(Matrix));
if (extOffset == NULL)
{
@ -6721,28 +6721,15 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
if (animData.channels[j].sampler->interpolation != cgltf_interpolation_type_max_enum)
{
if (channel.target_path == cgltf_animation_path_type_translation)
{
boneChannels[boneIndex].translate = &animData.channels[j];
}
else if (channel.target_path == cgltf_animation_path_type_rotation)
{
boneChannels[boneIndex].rotate = &animData.channels[j];
}
else if (channel.target_path == cgltf_animation_path_type_scale)
{
boneChannels[boneIndex].scale = &animData.channels[j];
}
else
{
TRACELOG(LOG_WARNING, "MODEL: [%s] Unsupported target_path on channel %d's sampler for animation %d. Skipping.", fileName, j, a);
}
if (channel.target_path == cgltf_animation_path_type_translation) boneChannels[boneIndex].translate = &animData.channels[j];
else if (channel.target_path == cgltf_animation_path_type_rotation) boneChannels[boneIndex].rotate = &animData.channels[j];
else if (channel.target_path == cgltf_animation_path_type_scale) boneChannels[boneIndex].scale = &animData.channels[j];
else TRACELOG(LOG_WARNING, "MODEL: [%s] Unsupported target_path on channel %d's sampler for animation %d. Skipping.", fileName, j, a);
}
else TRACELOG(LOG_WARNING, "MODEL: [%s] Invalid interpolation curve encountered for GLTF animation.", fileName);
float time = 0.0f;
cgltf_bool result = cgltf_accessor_read_float(channel.sampler->input, channel.sampler->input->count - 1, &time, 1);
result = cgltf_accessor_read_float(channel.sampler->input, channel.sampler->input->count - 1, &time, 1);
if (!result)
{
TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to load input time", fileName);
@ -6894,8 +6881,6 @@ static Model LoadVOX(const char *fileName)
unsigned short *pindices = voxarray.indices.array; // 5461*6*6 = 196596 indices max per mesh
int size = 0;
for (int i = 0; i < meshescount; i++)
{
Mesh *pmesh = &model.meshes[i];
@ -6904,25 +6889,22 @@ static Model LoadVOX(const char *fileName)
// Copy vertices
pmesh->vertexCount = (int)fmin(verticesMax, verticesRemain);
size = pmesh->vertexCount*sizeof(float)*3;
pmesh->vertices = (float *)RL_MALLOC(size);
memcpy(pmesh->vertices, pvertices, size);
pmesh->vertices = (float *)RL_CALLOC(pmesh->vertexCount*3, sizeof(float));
memcpy(pmesh->vertices, pvertices, pmesh->vertexCount*3*sizeof(float));
// Copy normals
pmesh->normals = (float *)RL_MALLOC(size);
memcpy(pmesh->normals, pnormals, size);
pmesh->normals = (float *)RL_CALLOC(pmesh->vertexCount*3, sizeof(float));
memcpy(pmesh->normals, pnormals, pmesh->vertexCount*3*sizeof(float));
// Copy indices
size = voxarray.indices.used*sizeof(unsigned short);
pmesh->indices = (unsigned short *)RL_MALLOC(size);
memcpy(pmesh->indices, pindices, size);
pmesh->indices = (unsigned short *)RL_CALLOC(voxarray.indices.used, sizeof(unsigned short));
memcpy(pmesh->indices, pindices, voxarray.indices.used*sizeof(unsigned short));
pmesh->triangleCount = (pmesh->vertexCount/4)*2;
// Copy colors
size = pmesh->vertexCount*sizeof(Color);
pmesh->colors = (unsigned char *)RL_MALLOC(size);
memcpy(pmesh->colors, pcolors, size);
pmesh->colors = (unsigned char *)RL_CALLOC(pmesh->vertexCount*4, sizeof(unsigned char));
memcpy(pmesh->colors, pcolors, pmesh->vertexCount*4*sizeof(unsigned char));
// First material index
model.meshMaterial[i] = 0;

View File

@ -1701,7 +1701,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA
}
// NOTE: In case number of segments is odd, adding one last piece to the cake
if ((((unsigned int)segments)%2) == 1)
if ((segments & 1) == 1)
{
rlColor4ub(color.r, color.g, color.b, color.a);