[Bf-blender-cvs] [4130cad4891] master: Fix T101607: Changing Image source inadvertently clears file path

Jesse Yurkovich noreply at git.blender.org
Sun Oct 23 07:36:36 CEST 2022


Commit: 4130cad4891e0ccd568934b0ee5b505d1a933d0f
Author: Jesse Yurkovich
Date:   Sat Oct 22 20:22:31 2022 -0700
Branches: master
https://developer.blender.org/rB4130cad4891e0ccd568934b0ee5b505d1a933d0f

Fix T101607: Changing Image source inadvertently clears file path

This could result in wrong behavior depending on the order in which the
Image.filepath and Image.source fields are set from within Python for
example.

Caused by rB72ab6faf5d80

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

M	source/blender/blenkernel/intern/image.cc

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

diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index 51d8f02616f..eae8b454189 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -3082,16 +3082,10 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
         /* Free all but the first tile. */
         image_remove_all_tiles(ima);
 
-        /* If the remaining tile is generated, we need to again ensure that we
-         * wouldn't continue to use the old filepath.
-         *
-         * Otherwise, if this used to be a UDIM image, get the concrete filepath associated
+        /* If this used to be a UDIM image, get the concrete filepath associated
          * with the remaining tile and use that as the new filepath. */
         ImageTile *base_tile = BKE_image_get_tile(ima, 0);
-        if ((base_tile->gen_flag & IMA_GEN_TILE) != 0) {
-          ima->filepath[0] = '\0';
-        }
-        else if (BKE_image_is_filename_tokenized(ima->filepath)) {
+        if (BKE_image_is_filename_tokenized(ima->filepath)) {
           const bool was_relative = BLI_path_is_rel(ima->filepath);
 
           eUDIM_TILE_FORMAT tile_format;
@@ -3183,10 +3177,14 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
            * left. */
           image_remove_all_tiles(ima);
 
-          int remaining_tile_number = ((ImageTile *)ima->tiles.first)->tile_number;
+          ImageTile *base_tile = BKE_image_get_tile(ima, 0);
+          int remaining_tile_number = base_tile->tile_number;
           bool needs_final_cleanup = true;
 
-          /* Add in all the new tiles. */
+          /* Add in all the new tiles. As the image is proven to be on disk at this point, remove
+           * the generation flag from the remaining tile in case this was previously a generated
+           * image. */
+          base_tile->gen_flag &= ~IMA_GEN_TILE;
           LISTBASE_FOREACH (LinkData *, new_tile, &new_tiles) {
             int new_tile_number = POINTER_AS_INT(new_tile->data);
             BKE_image_add_tile(ima, new_tile_number, nullptr);
@@ -3202,6 +3200,11 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
         }
         BLI_freelistN(&new_tiles);
       }
+      else if (ima->filepath[0] != '\0') {
+        /* If the filepath is set at this point remove the generation flag. */
+        ImageTile *base_tile = BKE_image_get_tile(ima, 0);
+        base_tile->gen_flag &= ~IMA_GEN_TILE;
+      }
 
       if (iuser) {
         image_tag_reload(ima, nullptr, iuser, ima);



More information about the Bf-blender-cvs mailing list