Skip to content

Commit

Permalink
Delete after rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Aug 14, 2024
1 parent 855d87c commit a970994
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 19 additions & 13 deletions src/retro_achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<atlas_t*> atlases{};
std::unordered_map<std::string, atlas_tile_t> image_cache{};
ra_achievement_list_t achievement_list;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<std::mutex> lock(global_cache_mutex);
for (auto& image : images_to_destroy)
{
sg_destroy_image(image);
}
}

std::unique_lock<std::mutex> lock(ra_state->game_state->mutex);

for (atlas_t* atlas : ra_state->game_state->atlases)
Expand All @@ -1235,7 +1228,8 @@ void retro_achievements_update_atlases()
{
if (atlas->image.id != SG_INVALID_ID)
{
sg_destroy_image(atlas->image);
std::unique_lock<std::mutex> glock(global_cache_mutex);
images_to_destroy.push_back(atlas->image);
}
atlas->image.id = SG_INVALID_ID;
}
Expand Down Expand Up @@ -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<std::mutex> 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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/retro_achievements.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a970994

Please sign in to comment.