From 98eb11156854e102a0405af1a64b2266eea22368 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Sat, 16 Apr 2022 14:18:08 -0700 Subject: Fix T97366: Misdetection of numbers as UDIMs in certain filepaths In some circumstances singular files with numbers in their name (like turntable-1080p.png or frame-1042.png) might be detected as a UDIM. The root cause in this particular instance was because `BKE_image_get_tile_info` believed this file to be a tiled texture and replaced the filename with a tokenized version of it. However, later on, the code inside `image_open_single` did not believe it was tiled because only 1 file was detected and our tiled textures require at least 2. This discrepancy lead to the broken filename situation. This was a regression since rB180b66ae8a1f as that introduced the tokenization changes. Differential Revision: https://developer.blender.org/D14667 --- source/blender/blenkernel/intern/image.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index 482537d7fa9..53ec148fd2d 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -3106,7 +3106,7 @@ bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, eUDIM_TILE_FORMAT tile_format; char *udim_pattern = BKE_image_get_tile_strformat(filename, &tile_format); - bool is_udim = true; + bool all_valid_udim = true; int min_udim = IMA_UDIM_MAX + 1; int max_udim = 0; int id; @@ -3124,7 +3124,7 @@ bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, } if (id < 1001 || id > IMA_UDIM_MAX) { - is_udim = false; + all_valid_udim = false; break; } @@ -3135,7 +3135,10 @@ bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, BLI_filelist_free(dirs, dirs_num); MEM_SAFE_FREE(udim_pattern); - if (is_udim && min_udim <= IMA_UDIM_MAX) { + /* Ensure that all discovered UDIMs are valid and that there's at least 2 files in total. + * Downstream code checks the range value to determine tiled-ness; it's important we match that + * expectation here too (T97366). */ + if (all_valid_udim && min_udim <= IMA_UDIM_MAX && max_udim > min_udim) { BLI_join_dirfile(filepath, FILE_MAX, dirname, filename); *r_tile_start = min_udim; -- cgit v1.2.3