Skip to content

Commit

Permalink
fix crash showing achievement game placard when threaded video enable…
Browse files Browse the repository at this point in the history
…d and game image not cached
  • Loading branch information
Jamiras committed Dec 13, 2023
1 parent c4faac0 commit 1893850
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cheevos/cheevos.c
Original file line number Diff line number Diff line change
Expand Up @@ -2463,15 +2463,15 @@ static void rcheevos_client_load_game_callback(int result,
}

#ifdef HAVE_THREADS
if (!task_is_on_main_thread())
if (!video_driver_is_threaded() && !task_is_on_main_thread())
{
/* have to "schedule" this. game image should not be loaded on background thread */
rcheevos_locals.queued_command = CMD_CHEEVOS_NON_COMMAND;
rcheevos_locals.game_placard_requested = true;
}
else
rcheevos_show_game_placard();
#endif
rcheevos_show_game_placard();

rcheevos_finalize_game_load(client);

Expand Down
15 changes: 9 additions & 6 deletions cheevos/cheevos_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,15 @@ uintptr_t rcheevos_get_badge_texture(const char* badge, bool locked, bool downlo
if (!badge || !badge[0])
return 0;

/* OpenGL driver crashes if gfx_display_reset_textures_list is called on a background thread */
if (!task_is_on_main_thread())
{
CHEEVOS_ERR(RCHEEVOS_TAG "attempt to load badge %s from background thread", badge);
retro_assert(task_is_on_main_thread());
}
#ifdef HAVE_THREADS
/* The OpenGL driver crashes if gfx_display_reset_textures_list is not called on the video thread.
* If threaded video is enabled, it'll automatically dispatch the request to the video thread.
* If threaded video is not enabled, just return null. The video thread should assume the image
* wasn't downloaded and check again in a few frames.
*/
if (!video_driver_is_threaded() && !task_is_on_main_thread())
return 0;
#endif

snprintf(badge_file, sizeof(badge_file), "%s%s%s", badge,
locked ? "_lock" : "", FILE_PATH_PNG_EXTENSION);
Expand Down
5 changes: 5 additions & 0 deletions gfx/video_thread_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,11 @@ unsigned video_thread_texture_load(void *data, custom_command_method_t func)
if (!thr)
return 0;

/* if we're already on the video thread, just call the function, otherwise
* we may deadlock with ourself waiting for the packet to be processed. */
if (sthread_get_thread_id(thr->thread) == sthread_get_current_thread_id())
return func(data);

pkt.type = CMD_CUSTOM_COMMAND;
pkt.data.custom_command.method = func;
pkt.data.custom_command.data = data;
Expand Down

0 comments on commit 1893850

Please sign in to comment.