Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] GLFW does not use Raylib-provided RL_*ALLOC macros for memory allocations #4776

Closed
sleeptightAnsiC opened this issue Feb 18, 2025 · 0 comments · Fixed by #4777
Closed

Comments

@sleeptightAnsiC
Copy link
Contributor

Raylib has a support for providing custom heap memory allocators by defining RL_MALLOC / RL_CALLOC / RL_REALLOC / RL_FREE macros. GLFW supports this too, but with function pointers passed into glfwInitAllocator() call. Currently, raylib does not use glfwInitAllocator anywhere, and so GLFW always uses default LibC allocators, which is undesired.

I noticed that there is some code in src/platforms/rcore_desktop_glfw.c that was meant to support this, but it is currently commented-out with a TODO note:

// Initialize platform: graphics, inputs and more
int InitPlatform(void)
{
glfwSetErrorCallback(ErrorCallback);
/*
// TODO: Setup GLFW custom allocators to match raylib ones
const GLFWallocator allocator = {
.allocate = MemAlloc,
.deallocate = MemFree,
.reallocate = MemRealloc,
.user = NULL
};
glfwInitAllocator(&allocator);
*/

Related to #4751

[I'll make a PR for this in a moment]

sleeptightAnsiC added a commit to sleeptightAnsiC/raylib that referenced this issue Feb 18, 2025
Raylib allows for providing custom allocators via macros.
GLFW supports this too, but via function pointers.

Make sure that GLFW uses those Raylib macros, by wrapping them in
function calls and setting them up inside of InitPlatform().
This is possible because of glfwInitAllocator() and GLFWallocator.

Fixes: raysan5#4776
Relates-to: raysan5#4751
@sleeptightAnsiC sleeptightAnsiC changed the title [rcore] GLFW does not use Raylib-provided RL_*alloc macros for memory allocations [rcore] GLFW does not use Raylib-provided RL_*ALLOC macros for memory allocations Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant