[Bf-blender-cvs] [0a72fc642dd] override-recursive-resync: ID management: remapping: add flag to enforce refcounting handling.

Bastien Montagne noreply at git.blender.org
Wed May 26 18:01:30 CEST 2021


Commit: 0a72fc642dd7232de83d43d39113c3202bb54978
Author: Bastien Montagne
Date:   Wed May 26 11:52:24 2021 +0200
Branches: override-recursive-resync
https://developer.blender.org/rB0a72fc642dd7232de83d43d39113c3202bb54978

ID management: remapping: add flag to enforce refcounting handling.

While indeally we should only skip refcounting when relevant tag is set,
doing this in remapping code is too risky for now.

Related to previous commit and T88555.

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

M	source/blender/blenkernel/BKE_lib_remap.h
M	source/blender/blenkernel/intern/lib_remap.c

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

diff --git a/source/blender/blenkernel/BKE_lib_remap.h b/source/blender/blenkernel/BKE_lib_remap.h
index 705d2b030e5..e806dedc14c 100644
--- a/source/blender/blenkernel/BKE_lib_remap.h
+++ b/source/blender/blenkernel/BKE_lib_remap.h
@@ -85,6 +85,10 @@ enum {
    * freed ones).
    */
   ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS = 1 << 7,
+  /** Force handling user count even for IDs that are outside of Main (used in some cases when
+   * dealing with IDs temporarily out of Main, but which will be put in it ultimately).
+   */
+  ID_REMAP_FORCE_USER_REFCOUNT = 1 << 8,
 };
 
 /* Note: Requiring new_id to be non-null, this *may* not be the case ultimately,
diff --git a/source/blender/blenkernel/intern/lib_remap.c b/source/blender/blenkernel/intern/lib_remap.c
index b32b97dc250..2641208897e 100644
--- a/source/blender/blenkernel/intern/lib_remap.c
+++ b/source/blender/blenkernel/intern/lib_remap.c
@@ -137,6 +137,7 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data)
                                 (id_remap_data->flag & ID_REMAP_FORCE_NEVER_NULL_USAGE) == 0);
     const bool skip_reference = (id_remap_data->flag & ID_REMAP_SKIP_OVERRIDE_LIBRARY) != 0;
     const bool skip_never_null = (id_remap_data->flag & ID_REMAP_SKIP_NEVER_NULL_USAGE) != 0;
+    const bool force_user_refcount = (id_remap_data->flag & ID_REMAP_FORCE_USER_REFCOUNT) != 0;
 
 #ifdef DEBUG_PRINT
     printf(
@@ -203,16 +204,16 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data)
         }
       }
       if (cb_flag & IDWALK_CB_USER) {
-        /* NOTE: We don't user-count IDs which are not in the main database.
+        /* NOTE: by default we don't user-count IDs which are not in the main database.
          * This is because in certain conditions we can have data-blocks in
          * the main which are referencing data-blocks outside of it.
          * For example, BKE_mesh_new_from_object() called on an evaluated
          * object will cause such situation.
          */
-        if ((old_id->tag & LIB_TAG_NO_MAIN) == 0) {
+        if (force_user_refcount || (old_id->tag & LIB_TAG_NO_MAIN) == 0) {
           id_us_min(old_id);
         }
-        if (new_id != NULL && (new_id->tag & LIB_TAG_NO_MAIN) == 0) {
+        if (new_id != NULL && (force_user_refcount || (new_id->tag & LIB_TAG_NO_MAIN) == 0)) {
           /* We do not want to handle LIB_TAG_INDIRECT/LIB_TAG_EXTERN here. */
           new_id->us++;
         }



More information about the Bf-blender-cvs mailing list