Fix file/asset thumbnails causing constant stream of notifiers

The thumbnail caching continuously sends `ND_SPACE_FILE_PREVIEW`
notifiers via a timer. But this timer was never ended properly after
thumbnails are fully loaded into the cache.
Wouldn't actually cause a refresh or redraw, send and process the
notifiers.

I already tried to avoid this for the asset view template, but
apparently that wasn't working correctly. For the File/Asset Browser I
never applied that fix to avoid possible regressions before the release.
This commit is contained in:
Julian Eisel 2022-01-20 18:21:57 +01:00
parent 902a103f80
commit d552b3c0c0
Notes: blender-bot 2023-02-14 01:07:44 +01:00
Referenced by issue #91807, Closing blender when you have had a file browser thumbnail view triggers an assert
2 changed files with 10 additions and 5 deletions

View File

@ -906,7 +906,8 @@ void file_draw_list(const bContext *C, ARegion *region)
* since it's filelist_file_cache_block() and filelist_cache_previews_update()
* which controls previews task. */
{
const bool previews_running = filelist_cache_previews_running(files);
const bool previews_running = filelist_cache_previews_running(files) &&
!filelist_cache_previews_done(files);
// printf("%s: preview task: %d\n", __func__, previews_running);
if (previews_running && !sfile->previews_timer) {
sfile->previews_timer = WM_event_add_timer_notifier(

View File

@ -339,7 +339,10 @@ typedef struct FileListEntryCache {
/* Previews handling. */
TaskPool *previews_pool;
ThreadQueue *previews_done;
size_t previews_todo_count;
/** Counter for previews that are not fully loaded and ready to display yet. So includes all
* previews either in `previews_pool` or `previews_done`. #filelist_cache_previews_update() makes
* previews in `preview_done` ready for display, so the counter is decremented there. */
int previews_todo_count;
} FileListEntryCache;
/* FileListCache.flags */
@ -1647,7 +1650,6 @@ static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdat
preview_taskdata->preview = NULL;
BLI_thread_queue_push(cache->previews_done, preview);
atomic_fetch_and_sub_z(&cache->previews_todo_count, 1);
// printf("%s: End (%d)...\n", __func__, threadid);
}
@ -1689,6 +1691,7 @@ static void filelist_cache_previews_clear(FileListEntryCache *cache)
}
MEM_freeN(preview);
}
cache->previews_todo_count = 0;
}
}
@ -1759,7 +1762,6 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry
preview->icon_id = BKE_icon_imbuf_create(imbuf);
}
BLI_thread_queue_push(cache->previews_done, preview);
atomic_fetch_and_sub_z(&cache->previews_todo_count, 1);
}
else {
if (entry->redirection_path) {
@ -1780,6 +1782,7 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry
true,
filelist_cache_preview_freef);
}
cache->previews_todo_count++;
}
static void filelist_cache_init(FileListEntryCache *cache, size_t cache_size)
@ -2693,6 +2696,7 @@ bool filelist_cache_previews_update(FileList *filelist)
}
MEM_freeN(preview);
cache->previews_todo_count--;
}
return changed;
@ -2714,7 +2718,7 @@ bool filelist_cache_previews_done(FileList *filelist)
}
return (cache->previews_pool == NULL) || (cache->previews_done == NULL) ||
(cache->previews_todo_count == (size_t)BLI_thread_queue_len(cache->previews_done));
(cache->previews_todo_count == 0);
}
/* would recognize .blend as well */