add tracy memory tracking to SDL
This commit is contained in:
parent
f1ffbbcfda
commit
1220cf6e7a
37
src/main.cpp
37
src/main.cpp
@ -626,7 +626,44 @@ V2 get_floor_intersection_of_mouse(V2 mouse_pos) {
|
||||
return floor_intersection.xy;
|
||||
}
|
||||
|
||||
#ifdef TRACY_ENABLE
|
||||
SDL_malloc_func sdl_malloc = NULL;
|
||||
SDL_calloc_func sdl_calloc = NULL;
|
||||
SDL_realloc_func sdl_realloc = NULL;
|
||||
SDL_free_func sdl_free = NULL;
|
||||
|
||||
void setup_memory_functions() {
|
||||
SDL_GetMemoryFunctions(&sdl_malloc, &sdl_calloc, &sdl_realloc, &sdl_free);
|
||||
SDL_SetMemoryFunctions(
|
||||
[](size_t size) -> void * {
|
||||
void *result = sdl_malloc(size);
|
||||
TracyAllocN(result, size, "SDL");
|
||||
return result;
|
||||
},
|
||||
[](size_t nmemb, size_t size) -> void * {
|
||||
void *result = sdl_calloc(nmemb, size);
|
||||
TracyAllocN(result, nmemb * size, "SDL");
|
||||
return result;
|
||||
},
|
||||
[](void *mem, size_t size) -> void * {
|
||||
void *result = sdl_realloc(mem, size);
|
||||
TracyFreeN(mem, "SDL");
|
||||
TracyAllocN(result, size, "SDL");
|
||||
return result;
|
||||
},
|
||||
[](void *mem) {
|
||||
TracyFreeN(mem, "SDL");
|
||||
sdl_free(mem);
|
||||
}
|
||||
);
|
||||
}
|
||||
#else
|
||||
void setup_memory_functions() {}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
setup_memory_functions();
|
||||
|
||||
load_map();
|
||||
|
||||
#ifdef SDL_PLATFORM_LINUX
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user