Skip to content

Commit

Permalink
Missing images problem seems fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Apr 27, 2024
1 parent 3c273a3 commit 9bb9b2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6375,24 +6375,31 @@ void se_draw_menu_panel(){
remove(login_info_path);
rc_client_logout(ra_info.client);
}
rc_client_achievement_list_t* list = ra_info.achievement_list;
#ifdef DEBUG_RETRO_ACHIEVEMENTS
if (se_button("Dump atlases", (ImVec2){0,0})){
ra_dump_atlases();
for (int i = 0; i < list->num_buckets; i++){
for (int j = 0; j < list->buckets[i].num_achievements; j++){
printf("achievement pointer: %p\n", ra_info.achievement_images[i][j]);
}
}
}
#endif
mutex_lock(ra_get_mutex());
rc_client_achievement_list_t* list = ra_info.achievement_list;
if (list){
for (int i = 0; i < list->num_buckets; i++){
se_text(ICON_FK_LOCK " %s",list->buckets[i].label);
for (int j = 0; j < list->buckets[i].num_achievements; j++){
sg_image image;
ImVec2 uv0, uv1;
bool entered = false;
if(ra_info.achievement_images && ra_info.achievement_images[i] && ra_info.achievement_images[i][j]) {
atlas_tile_t* tile = ra_info.achievement_images[i][j];
uv0 = (ImVec2){ tile->x1, tile->y1 };
uv1 = (ImVec2){ tile->x2, tile->y2 };
image.id = tile->atlas_id;
entered = true;
}
#ifdef DEBUG_RETRO_ACHIEVEMENTS
char name[512];
Expand All @@ -6401,7 +6408,7 @@ void se_draw_menu_panel(){
int ofy = uv0.y * info.height;
int of1x = uv1.x * info.width;
int of1y = uv1.y * info.height;
snprintf(name,512,"%s (%d) %d %d %d %d",list->buckets[i].achievements[j]->title,image.id,ofx,ofy,of1x,of1y);
snprintf(name,512,"%s %p %p (%d) %d %d %d %d",list->buckets[i].achievements[j]->title, ra_info.achievement_images[i], ra_info.achievement_images[i][j], entered,ofx,ofy,of1x,of1y);
se_boxed_image_dual_label(name,list->buckets[i].achievements[j]->description, ICON_FK_SPINNER, image, 0, uv0, uv1);
#else
se_boxed_image_dual_label(list->buckets[i].achievements[j]->title,
Expand Down
21 changes: 16 additions & 5 deletions src/retro_achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ extern "C" void ra_log_callback(const char* message, const rc_client_t* client)
// We got some data (either by downloading it, or from the cache), let's handle it
void handle_downloaded_image(const char* url, atlas_tile_t** out_image)
{
printf("[rcheevos]: handling downloaded image\n");
downloaded_image_t* image = download_cache[url];
atlas_t* atlas = nullptr;

Expand Down Expand Up @@ -297,7 +296,12 @@ void handle_downloaded_image(const char* url, atlas_tile_t** out_image)
tile.y2 = (float)(offset_y + image->height) / atlas->pixel_stride;

// Pending callbacks are executed after ra_update_atlases which is what we want
pending_callbacks.push_back([out_image, &tile]() { *out_image = &tile; });
printf("Pushing back for %s\n", url);
std::string url_str = url;
pending_callbacks.push_back([out_image, &tile, url_str]() { *out_image = &tile;
printf("running callback for %s\n", url_str.c_str());
printf("out_image: %p\n", *out_image);
});
}

// This should be getting called from the UI thread only, either from the load game callback
Expand Down Expand Up @@ -326,12 +330,18 @@ void ra_get_image(const char* url, atlas_tile_t** out_image)
}
}

#ifdef DEBUG_RETRO_ACHIEVEMENTS
printf("Downloading image %s\n", url);
#endif

// The image is not already downloaded, let's download it
std::string url_str = url; // When this function returns, the const char* will be invalid, so we
// need to copy the contents to a string
https_request(http_request_e::GET, url_str, {}, {},
[out_image, url_str](const std::vector<uint8_t>& result) {
printf("downloaded: %s\n", url_str.c_str());
#ifdef DEBUG_RETRO_ACHIEVEMENTS
printf("Downloaded image %s\n", url_str.c_str());
#endif
std::unique_lock<std::mutex> lock(*synchronization_mutex);
rc_api_server_response_t response;
response.body = (const char*)result.data();
Expand Down Expand Up @@ -430,13 +440,14 @@ void ra_update_atlases()

atlas->image = sg_make_image(&desc);

if (atlas->resized && invalidated_id != SG_INVALID_ID)
if (atlas->resized)
{
for (auto& image : image_cache)
{
// Update the images to point to the new atlas instead
if (image.second.atlas_id == invalidated_id)
{
printf("Updating atlas id from %d to %d for %p\n", invalidated_id, atlas->image.id, &image.second);
image.second.atlas_id = atlas->image.id;
}
}
Expand Down Expand Up @@ -492,7 +503,7 @@ void ra_dump_atlases()
printf("There's %d atlas mappings\n", image_cache.size());
for (auto& image : image_cache)
{
printf("%s: (points to id: %d) %f %f %f %f\n", image.first.c_str(), image.second.atlas_id,
printf("%s (%p): (points to id: %d) %f %f %f %f\n", image.first.c_str(), &image.second, image.second.atlas_id,
image.second.x1, image.second.y1, image.second.x2, image.second.y2);
}

Expand Down

0 comments on commit 9bb9b2c

Please sign in to comment.