[Bf-blender-cvs] [b3dc1a17a0e] master: Fix BKE_image_ensure_tile_token being called with a full path

Campbell Barton noreply at git.blender.org
Fri Jan 7 05:20:09 CET 2022


Commit: b3dc1a17a0e7b7e38a8ece70ca0d353aff82c154
Author: Campbell Barton
Date:   Fri Jan 7 15:13:31 2022 +1100
Branches: master
https://developer.blender.org/rBb3dc1a17a0e7b7e38a8ece70ca0d353aff82c154

Fix BKE_image_ensure_tile_token being called with a full path

Assert that only the file name component is passed in
since special handling for UDIM should only be applied to the file name.

Also remove an unnecessary NULL check on the filename argument.

===================================================================

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenlib/BLI_path_util.h
M	source/blender/blenloader/intern/versioning_300.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index eb7738b9307..7b87189a13f 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -436,6 +436,7 @@ typedef enum {
 
 /**
  * Ensures that `filename` contains a UDIM token if we find a supported format pattern.
+ * \note This must only be the name component (without slashes).
  */
 void BKE_image_ensure_tile_token(char *filename);
 
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 2d4366846aa..4899c3671aa 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -4062,9 +4062,8 @@ bool BKE_image_fill_tile(struct Image *ima,
 
 void BKE_image_ensure_tile_token(char *filename)
 {
-  if (filename == NULL) {
-    return;
-  }
+  BLI_assert_msg(BLI_path_slash_find(filename) == NULL,
+                 "Only the file-name component should be used!");
 
   /* Is there a '<' character in the filename? Assume tokens already present. */
   if (strstr(filename, "<") != NULL) {
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 85d4ed4a307..16f479cb3b8 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -142,7 +142,11 @@ bool BLI_path_contains(const char *container_path,
                        const char *containee_path) ATTR_WARN_UNUSED_RESULT;
 
 /**
- * Returns pointer to the rightmost path separator in string.
+ * \return pointer to the leftmost path separator in string (or NULL when not found).
+ */
+const char *BLI_path_slash_find(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+/**
+ * \return pointer to the rightmost path separator in string (or NULL when not found).
  */
 const char *BLI_path_slash_rfind(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 /**
@@ -154,10 +158,6 @@ int BLI_path_slash_ensure(char *string) ATTR_NONNULL();
  * Removes the last slash and everything after it to the end of string, if there is one.
  */
 void BLI_path_slash_rstrip(char *string) ATTR_NONNULL();
-/**
- * Returns pointer to the leftmost path separator in string. Not actually used anywhere.
- */
-const char *BLI_path_slash_find(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 /**
  * Changes to the path separators to the native ones for this OS.
  */
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 5cfc937acf1..152684db8f1 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -824,7 +824,8 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
     /* Ensure tiled image sources contain a UDIM token. */
     LISTBASE_FOREACH (Image *, ima, &bmain->images) {
       if (ima->source == IMA_SRC_TILED) {
-        BKE_image_ensure_tile_token(ima->filepath);
+        char *filename = (char *)BLI_path_basename(ima->filepath);
+        BKE_image_ensure_tile_token(filename);
       }
     }
   }



More information about the Bf-blender-cvs mailing list