From a970994aba003ed4f69db4a42016da696add80ab Mon Sep 17 00:00:00 2001 From: offtkp Date: Wed, 14 Aug 2024 04:04:55 +0300 Subject: [PATCH] Delete after rendering --- src/main.c | 1 + src/retro_achievements.cpp | 32 +++++++++++++++++++------------- src/retro_achievements.h | 2 ++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main.c b/src/main.c index c22811ea5..2aa51f54e 100644 --- a/src/main.c +++ b/src/main.c @@ -7650,6 +7650,7 @@ static void frame(void) { se_emscripten_flush_fs(); gui_state.last_saved_settings=gui_state.settings; } + retro_achievements_delete_retired_atlases(); } void se_load_settings(){ se_load_recent_games_list(); diff --git a/src/retro_achievements.cpp b/src/retro_achievements.cpp index aa558fa47..5345f9f9d 100644 --- a/src/retro_achievements.cpp +++ b/src/retro_achievements.cpp @@ -136,7 +136,7 @@ struct ra_game_state_t { ~ra_game_state_t(); - atlas_tile_t* game_image; + atlas_tile_t* game_image = nullptr; std::vector atlases{}; std::unordered_map image_cache{}; ra_achievement_list_t achievement_list; @@ -1095,12 +1095,13 @@ void retro_achievements_shutdown() rc_client_destroy(ra_state->rc_client); + ra_state->game_state.reset(); + for (auto& image : images_to_destroy) { sg_destroy_image(image); } - - ra_state->game_state.reset(); + images_to_destroy.clear(); delete ra_state; @@ -1219,14 +1220,6 @@ void retro_achievements_update_atlases() return; // probably a lot of outstanding requests hold the mutex, let's wait for them to // finish before we try to lock ourselves to prevent stuttering - { - std::unique_lock lock(global_cache_mutex); - for (auto& image : images_to_destroy) - { - sg_destroy_image(image); - } - } - std::unique_lock lock(ra_state->game_state->mutex); for (atlas_t* atlas : ra_state->game_state->atlases) @@ -1235,7 +1228,8 @@ void retro_achievements_update_atlases() { if (atlas->image.id != SG_INVALID_ID) { - sg_destroy_image(atlas->image); + std::unique_lock glock(global_cache_mutex); + images_to_destroy.push_back(atlas->image); } atlas->image.id = SG_INVALID_ID; } @@ -1281,7 +1275,19 @@ void retro_achievements_update_atlases() atlas->resized = false; } } -bool retro_achievements_has_game_loaded(){ + +void retro_achievements_delete_retired_atlases() +{ + std::unique_lock lock(global_cache_mutex); + for (auto& image : images_to_destroy) + { + sg_destroy_image(image); + } + images_to_destroy.clear(); +} + +bool retro_achievements_has_game_loaded() +{ return rc_client_get_game_info(ra_state->rc_client)!=NULL; } diff --git a/src/retro_achievements.h b/src/retro_achievements.h index 952a4bda2..7e11866ac 100644 --- a/src/retro_achievements.h +++ b/src/retro_achievements.h @@ -43,6 +43,8 @@ const char* retro_achievements_get_login_error(); void retro_achievements_update_atlases(); +void retro_achievements_delete_retired_atlases(); + void retro_achievements_keep_alive(); void retro_achievements_draw_notifications(float left, float top, float screen_width);