Skip to content

Commit

Permalink
Support custom memory management macros
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
raysan5 committed Apr 23, 2019
1 parent 8ed71b9 commit e67ebab
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 339 deletions.
24 changes: 12 additions & 12 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ void EndDrawing(void)
unsigned char *screenData = rlReadScreenPixels(screenWidth, screenHeight);
GifWriteFrame(screenData, screenWidth, screenHeight, 10, 8, false);

free(screenData); // Free image data
RL_FREE(screenData); // Free image data
}

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

ExportImage(image, path);
free(imgData);
RL_FREE(imgData);

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

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

int counter = 0;
struct dirent *ent;
Expand Down Expand Up @@ -1776,9 +1776,9 @@ void ClearDirectoryFiles(void)
{
if (dirFilesCount > 0)
{
for (int i = 0; i < dirFilesCount; i++) free(dirFilesPath[i]);
for (int i = 0; i < dirFilesCount; i++) RL_FREE(dirFilesPath[i]);

free(dirFilesPath);
RL_FREE(dirFilesPath);
dirFilesCount = 0;
}
}
Expand Down Expand Up @@ -1808,9 +1808,9 @@ void ClearDroppedFiles(void)
{
if (dropFilesCount > 0)
{
for (int i = 0; i < dropFilesCount; i++) free(dropFilesPath[i]);
for (int i = 0; i < dropFilesCount; i++) RL_FREE(dropFilesPath[i]);

free(dropFilesPath);
RL_FREE(dropFilesPath);

dropFilesCount = 0;
}
Expand Down Expand Up @@ -1925,7 +1925,7 @@ void OpenURL(const char *url)
}
else
{
char *cmd = (char *)calloc(strlen(url) + 10, sizeof(char));
char *cmd = (char *)RL_CALLOC(strlen(url) + 10, sizeof(char));

#if defined(_WIN32)
sprintf(cmd, "explorer %s", url);
Expand All @@ -1935,7 +1935,7 @@ void OpenURL(const char *url)
sprintf(cmd, "open '%s'", url);
#endif
system(cmd);
free(cmd);
RL_FREE(cmd);
}
}

Expand Down Expand Up @@ -3455,11 +3455,11 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
{
ClearDroppedFiles();

dropFilesPath = (char **)malloc(sizeof(char *)*count);
dropFilesPath = (char **)RL_MALLOC(sizeof(char *)*count);

for (int i = 0; i < count; i++)
{
dropFilesPath[i] = (char *)malloc(sizeof(char)*MAX_FILEPATH_LENGTH);
dropFilesPath[i] = (char *)RL_MALLOC(sizeof(char)*MAX_FILEPATH_LENGTH);
strcpy(dropFilesPath[i], paths[i]);
}

Expand Down
Loading

0 comments on commit e67ebab

Please sign in to comment.