Hello,
I am currently working on a project where I am integrating a custom TLSF memory allocator into SDL3. I have connected this custom allocator to SDL’s memory functions using SDL_SetMemoryFunctions()
. Everything seems to be working fine, except for when I call SDL_Quit()
.
Even when reduced to running code that just connects my allocator, sets it up, and then runs SDL_Init() and SDL_Quit(), it exits with code 42 after the SDL_Quit()
call. Following GDB I have found that the issue seems to be a assert within the mutex file that fails. However, given that TLSF isn’t a thread safe memory allocator, I wrapped all my memory allocation functions within locked SDL_Mutex’s but I still regain the same error. And really struggle to imagine how my allocator might not be thread-safe.
Here is pretty much the wrapper that all my memory functions are wrapped in.
void *sdl_tlsf_malloc(size_t bytes) {
SDL_LockMutex(tlsf_lock);
SDL_Log("Malloc Called on %ld bytes\n", bytes);
// Check if we have enough memory to allocate
void *ptr = tlsf_malloc(active_instance.instance, bytes);
// Update metadata structs
SDL_UnlockMutex(tlsf_lock);
return ptr;
}
Has anyone encountered a similar issue or does anyone have any insights on what might be causing this? Any help would be greatly appreciated. Maybe I’m using mutex’s wrong and missing something? I haven’t worked with locks and mutex’s since my System Progamming course so I’m a bit rusty and could see myself making assumptions about how they work.
Thank you in advance!