Fix: Fix most cases of asset browser preview flickering on undo/redo

Mitigates #93726.

With this asset previews will no longer flicker in the asset browser
on actions like undo, redo or when using "Adjust Last Operation" if
the asset library doesn't contain assets from the current file.

Previews of assets from the current file would have to be cleared on
undo & redo, because their memory location can change then. However the
file browser's data model didn't allow clearing just these previews, so
previews from external assets would have to be reloaded from disk too,
causing the flickering.

Noticed we can trivially skip clearing of previews if there are no
assets from the current file anyway. This mitigates the issue quite a
bit until preview handling is rewritten, see #122439.
This commit is contained in:
Julian Eisel
2025-03-04 17:45:37 +01:00
parent a3baf60df4
commit 7e99e575a4

View File

@@ -1498,7 +1498,9 @@ static int filelist_intern_free_main_files(FileList *filelist)
removed_counter++;
}
MEM_SAFE_FREE(filelist_intern->filtered);
if (removed_counter > 0) {
MEM_SAFE_FREE(filelist_intern->filtered);
}
return removed_counter;
}
@@ -1914,6 +1916,11 @@ static void filelist_clear_main_files(FileList *filelist,
if (filelist->filelist.entries_num == FILEDIR_NBR_ENTRIES_UNSET) {
return;
}
const int removed_files = filelist_intern_free_main_files(filelist);
/* File list contains no main files to clear. */
if (removed_files == 0) {
return;
}
filelist_tag_needs_filtering(filelist);
@@ -1921,8 +1928,6 @@ static void filelist_clear_main_files(FileList *filelist,
filelist_cache_clear(&filelist->filelist_cache, filelist->filelist_cache.size);
}
const int removed_files = filelist_intern_free_main_files(filelist);
filelist->filelist.entries_num -= removed_files;
filelist->filelist.entries_filtered_num = FILEDIR_NBR_ENTRIES_UNSET;
BLI_assert(filelist->filelist.entries_num > FILEDIR_NBR_ENTRIES_UNSET);