Skip to content

Commit

Permalink
Fix aseprite cache from mem bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyGaul committed Mar 8, 2025
1 parent 9caa070 commit 72ccf9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/cute_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ int cf_app_draw_onto_screen(bool clear)

// Stretch the app canvas onto the backbuffer canvas.
Uint32 w, h;
SDL_GPUTexture* swapchain_tex;
SDL_GPUTexture* swapchain_tex = NULL;
if (SDL_AcquireGPUSwapchainTexture(app->cmd, app->window, &swapchain_tex, &w, &h) && swapchain_tex) {
// Blit onto the screen.
SDL_GPUBlitRegion src = {
Expand All @@ -533,10 +533,9 @@ int cf_app_draw_onto_screen(bool clear)
};
SDL_BlitGPUTexture(app->cmd, &blit_info);
} else {
// @Hack - Avoid large resource cycle chains gobbling up RAM when GPU-bound.
// Waiting on response from Evan on proper fix:
// Avoid large resource cycle chains gobbling up RAM when GPU-bound.
// https://discourse.libsdl.org/t/sdl-gpu-cycle-difficulties/55188
SDL_WaitForGPUIdle(app->device);
SDL_CancelGPUCommandBuffer(app->cmd);
}

// Dear ImGui draw.
Expand Down
17 changes: 15 additions & 2 deletions src/cute_aseprite_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void s_sprite(CF_AsepriteCacheEntry entry, CF_Sprite* sprite)
}
}

CF_Result cf_aseprite_cache_load_from_memory(const char* unique_name, const void* data, int sz, CF_Sprite* sprite_out)
static CF_Result s_aseprite_cache_load_from_memory(const char* unique_name, const void* data, int sz, CF_Sprite* sprite_out)
{
ase_t* ase = cute_aseprite_load_from_memory(data, (int)sz, NULL);
if (!ase) return cf_result_error("Unable to open ase file at `aseprite_path`.");
Expand Down Expand Up @@ -226,6 +226,19 @@ CF_Result cf_aseprite_cache_load_from_memory(const char* unique_name, const void
return cf_result_success();
}

CF_Result cf_aseprite_cache_load_from_memory(const char* unique_name, const void* data, int sz, CF_Sprite* sprite_out)
{
// First see if this ase was already cached.
unique_name = sintern(unique_name);
auto entry_ptr = cache->aseprites.try_find(unique_name);
if (entry_ptr) {
s_sprite(*entry_ptr, sprite_out);
return cf_result_success();
}

return s_aseprite_cache_load_from_memory(unique_name, data, sz, sprite_out);
}

CF_Result cf_aseprite_cache_load(const char* aseprite_path, CF_Sprite* sprite)
{
// First see if this ase was already cached.
Expand All @@ -242,7 +255,7 @@ CF_Result cf_aseprite_cache_load(const char* aseprite_path, CF_Sprite* sprite)
if (!data) return cf_result_error("Unable to open ase file at `aseprite_path`.");
CF_DEFER(CF_FREE(data));

return cf_aseprite_cache_load_from_memory(aseprite_path, data, (int)sz, sprite);
return s_aseprite_cache_load_from_memory(aseprite_path, data, (int)sz, sprite);
}

void cf_aseprite_cache_unload(const char* aseprite_path)
Expand Down

0 comments on commit 72ccf9c

Please sign in to comment.