diff --git a/tasks/task_pl_thumbnail_download.c b/tasks/task_pl_thumbnail_download.c index ecf24e2538..4471601f77 100644 --- a/tasks/task_pl_thumbnail_download.c +++ b/tasks/task_pl_thumbnail_download.c @@ -71,7 +71,7 @@ typedef struct pl_thumb_handle typedef struct pl_entry_id { - playlist_t *playlist; + char *playlist_path; size_t idx; } pl_entry_id_t; @@ -476,12 +476,40 @@ static void cb_task_pl_entry_thumbnail_refresh_menu( pl_thumb_handle_t *pl_thumb = NULL; const char *thumbnail_path = NULL; const char *left_thumbnail_path = NULL; + playlist_t *current_playlist = playlist_get_cached(); + menu_handle_t *menu = NULL; bool do_refresh = false; if (!task) return; pl_thumb = (pl_thumb_handle_t*)task->state; + if (!pl_thumb) + return; + + if (!pl_thumb->thumbnail_path_data) + return; + + /* Only refresh if current playlist hasn't changed, + * and menu selection pointer is on the same entry + * (Note: this is crude, but it's sufficient to prevent + * 'refresh' from getting spammed when switching + * playlists or scrolling through one playlist at + * maximum speed with on demand downloads enabled) */ + + if (!current_playlist) + return; + + if (string_is_empty(playlist_get_conf_path(current_playlist))) + return; + + if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) + return; + + if (((pl_thumb->list_index != menu_navigation_get_selection()) && + (pl_thumb->list_index != menu->rpl_entry_selection_ptr)) || + !string_is_equal(pl_thumb->playlist_path, playlist_get_conf_path(current_playlist))) + return; /* Only refresh if left/right thumbnails did not exist * when the task began, but do exist now @@ -642,8 +670,7 @@ static bool task_pl_entry_thumbnail_finder(retro_task_t *task, void *user_data) return false; return (entry_id->idx == pl_thumb->list_index) && - string_is_equal(playlist_get_conf_path(entry_id->playlist), - playlist_get_conf_path(pl_thumb->playlist)); + string_is_equal(entry_id->playlist_path, pl_thumb->playlist_path); } bool task_push_pl_entry_thumbnail_download( @@ -658,12 +685,15 @@ bool task_push_pl_entry_thumbnail_download( retro_task_t *task = task_init(); pl_thumb_handle_t *pl_thumb = (pl_thumb_handle_t*)calloc(1, sizeof(pl_thumb_handle_t)); pl_entry_id_t *entry_id = (pl_entry_id_t*)calloc(1, sizeof(pl_entry_id_t)); + char *playlist_path = NULL; /* Sanity check */ if (!settings || !task || !pl_thumb || !playlist || !entry_id) goto error; - if (string_is_empty(system) || string_is_empty(settings->paths.directory_thumbnails)) + if (string_is_empty(system) || + string_is_empty(settings->paths.directory_thumbnails) || + string_is_empty(playlist_get_conf_path(playlist))) goto error; if (idx >= playlist_size(playlist)) @@ -675,9 +705,13 @@ bool task_push_pl_entry_thumbnail_download( string_is_equal(system, "video_history")) goto error; + /* Copy playlist path + * (required for task finder and menu refresh functionality) */ + playlist_path = strdup(playlist_get_conf_path(playlist)); + /* Concurrent download of thumbnails for the same * playlist entry is not allowed */ - entry_id->playlist = playlist; + entry_id->playlist_path = playlist_path; entry_id->idx = idx; find_data.func = task_pl_entry_thumbnail_finder; @@ -701,7 +735,7 @@ bool task_push_pl_entry_thumbnail_download( /* Configure handle */ pl_thumb->system = strdup(system); - pl_thumb->playlist_path = NULL; + pl_thumb->playlist_path = playlist_path; pl_thumb->dir_thumbnails = strdup(settings->paths.directory_thumbnails); pl_thumb->playlist = playlist; pl_thumb->thumbnail_path_data = NULL; @@ -736,5 +770,11 @@ error: entry_id = NULL; } + if (!string_is_empty(playlist_path)) + { + free(playlist_path); + playlist_path = NULL; + } + return false; }