Skip to content

Commit e67ebab

Browse files
committed
Support custom memory management macros
Users can define their custom memory management macros. NOTE: Most external libraries support custom macros in the same way, raylib should redefine those macros to raylib ones, to unify custom memory loading. That redefinition is only implemented as example for stb_image.h in [textures] module.
1 parent 8ed71b9 commit e67ebab

File tree

9 files changed

+365
-339
lines changed

9 files changed

+365
-339
lines changed

src/core.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ void EndDrawing(void)
11131113
unsigned char *screenData = rlReadScreenPixels(screenWidth, screenHeight);
11141114
GifWriteFrame(screenData, screenWidth, screenHeight, 10, 8, false);
11151115

1116-
free(screenData); // Free image data
1116+
RL_FREE(screenData); // Free image data
11171117
}
11181118

11191119
if (((gifFramesCounter/15)%2) == 1)
@@ -1595,7 +1595,7 @@ void TakeScreenshot(const char *fileName)
15951595
#endif
15961596

15971597
ExportImage(image, path);
1598-
free(imgData);
1598+
RL_FREE(imgData);
15991599

16001600
#if defined(PLATFORM_WEB)
16011601
// Download file from MEMFS (emscripten memory filesystem)
@@ -1742,8 +1742,8 @@ char **GetDirectoryFiles(const char *dirPath, int *fileCount)
17421742
ClearDirectoryFiles();
17431743

17441744
// Memory allocation for MAX_DIRECTORY_FILES
1745-
dirFilesPath = (char **)malloc(sizeof(char *)*MAX_DIRECTORY_FILES);
1746-
for (int i = 0; i < MAX_DIRECTORY_FILES; i++) dirFilesPath[i] = (char *)malloc(sizeof(char)*MAX_FILEPATH_LENGTH);
1745+
dirFilesPath = (char **)RL_MALLOC(sizeof(char *)*MAX_DIRECTORY_FILES);
1746+
for (int i = 0; i < MAX_DIRECTORY_FILES; i++) dirFilesPath[i] = (char *)RL_MALLOC(sizeof(char)*MAX_FILEPATH_LENGTH);
17471747

17481748
int counter = 0;
17491749
struct dirent *ent;
@@ -1776,9 +1776,9 @@ void ClearDirectoryFiles(void)
17761776
{
17771777
if (dirFilesCount > 0)
17781778
{
1779-
for (int i = 0; i < dirFilesCount; i++) free(dirFilesPath[i]);
1779+
for (int i = 0; i < dirFilesCount; i++) RL_FREE(dirFilesPath[i]);
17801780

1781-
free(dirFilesPath);
1781+
RL_FREE(dirFilesPath);
17821782
dirFilesCount = 0;
17831783
}
17841784
}
@@ -1808,9 +1808,9 @@ void ClearDroppedFiles(void)
18081808
{
18091809
if (dropFilesCount > 0)
18101810
{
1811-
for (int i = 0; i < dropFilesCount; i++) free(dropFilesPath[i]);
1811+
for (int i = 0; i < dropFilesCount; i++) RL_FREE(dropFilesPath[i]);
18121812

1813-
free(dropFilesPath);
1813+
RL_FREE(dropFilesPath);
18141814

18151815
dropFilesCount = 0;
18161816
}
@@ -1925,7 +1925,7 @@ void OpenURL(const char *url)
19251925
}
19261926
else
19271927
{
1928-
char *cmd = (char *)calloc(strlen(url) + 10, sizeof(char));
1928+
char *cmd = (char *)RL_CALLOC(strlen(url) + 10, sizeof(char));
19291929

19301930
#if defined(_WIN32)
19311931
sprintf(cmd, "explorer %s", url);
@@ -1935,7 +1935,7 @@ void OpenURL(const char *url)
19351935
sprintf(cmd, "open '%s'", url);
19361936
#endif
19371937
system(cmd);
1938-
free(cmd);
1938+
RL_FREE(cmd);
19391939
}
19401940
}
19411941

@@ -3455,11 +3455,11 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
34553455
{
34563456
ClearDroppedFiles();
34573457

3458-
dropFilesPath = (char **)malloc(sizeof(char *)*count);
3458+
dropFilesPath = (char **)RL_MALLOC(sizeof(char *)*count);
34593459

34603460
for (int i = 0; i < count; i++)
34613461
{
3462-
dropFilesPath[i] = (char *)malloc(sizeof(char)*MAX_FILEPATH_LENGTH);
3462+
dropFilesPath[i] = (char *)RL_MALLOC(sizeof(char)*MAX_FILEPATH_LENGTH);
34633463
strcpy(dropFilesPath[i], paths[i]);
34643464
}
34653465

0 commit comments

Comments
 (0)