[Bf-blender-cvs] [942353d8b04] id_override_static: Add needed option to handle or not override's reference pointer when remapping.

Bastien Montagne noreply at git.blender.org
Wed Oct 4 22:03:16 CEST 2017


Commit: 942353d8b04dfe4b3592cfd6834e0f5731109bf7
Author: Bastien Montagne
Date:   Wed Oct 4 22:01:30 2017 +0200
Branches: id_override_static
https://developer.blender.org/rB942353d8b04dfe4b3592cfd6834e0f5731109bf7

Add needed option to handle or not override's reference pointer when remapping.

There are cases where we'll want to also override the reference pointer
(when we actually switch that datablock itself), but in some specific
situations, like when creating a new override, we need to keep org
pointer here!

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

M	source/blender/blenkernel/BKE_library_query.h
M	source/blender/blenkernel/BKE_library_remap.h
M	source/blender/blenkernel/intern/library_override.c
M	source/blender/blenkernel/intern/library_query.c
M	source/blender/blenkernel/intern/library_remap.c

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

diff --git a/source/blender/blenkernel/BKE_library_query.h b/source/blender/blenkernel/BKE_library_query.h
index d6e7d98f371..b66fc0aab16 100644
--- a/source/blender/blenkernel/BKE_library_query.h
+++ b/source/blender/blenkernel/BKE_library_query.h
@@ -56,6 +56,9 @@ enum {
 	 * How to handle that kind of cases totally depends on what caller code is doing... */
 	IDWALK_CB_LOOPBACK = (1 << 4),
 
+	/** That ID is used as static override's reference by its owner. */
+	IDWALK_CB_STATIC_OVERRIDE_REFERENCE = (1 << 5),
+
 	/**
 	 * Adjusts #ID.us reference-count.
 	 * \note keep in sync with 'newlibadr_us' use in readfile.c
diff --git a/source/blender/blenkernel/BKE_library_remap.h b/source/blender/blenkernel/BKE_library_remap.h
index fd37fd762f4..3425ca011b7 100644
--- a/source/blender/blenkernel/BKE_library_remap.h
+++ b/source/blender/blenkernel/BKE_library_remap.h
@@ -51,6 +51,8 @@ enum {
 	 * This is needed e.g. in reload scenario, since we have to ensure remapping of Armature data of local proxy
 	 * is also performed. Usual nightmare... */
 	ID_REMAP_NO_INDIRECT_PROXY_DATA_USAGE = 1 << 4,
+	/* Do not remap static override pointers. */
+	ID_REMAP_SKIP_STATIC_OVERRIDE = 1 << 5,
 };
 
 /* Note: Requiring new_id to be non-null, this *may* not be the case ultimately, but makes things simpler for now. */
diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c
index 6585c388e21..c6ad7deaf63 100644
--- a/source/blender/blenkernel/intern/library_override.c
+++ b/source/blender/blenkernel/intern/library_override.c
@@ -155,12 +155,12 @@ ID *BKE_override_create_from(Main *bmain, ID *reference_id)
 	}
 	id_us_min(local_id);
 
-	/* Remapping *before* defining override (this will have to be fixed btw, remapping of ref pointer...). */
-	BKE_libblock_remap(bmain, reference_id, local_id, ID_REMAP_SKIP_INDIRECT_USAGE);
-
 	BKE_override_init(local_id, reference_id);
 	local_id->flag |= LIB_AUTOOVERRIDE;
 
+	/* Remapping, we obviously only want to affect local data (and not our own reference pointer to overriden ID). */
+	BKE_libblock_remap(bmain, reference_id, local_id, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_STATIC_OVERRIDE);
+
 	return local_id;
 }
 
diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c
index bd308991c79..5063fbaafcf 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -368,8 +368,8 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
 #define CALLBACK_INVOKE(check_id_super, cb_flag) \
 	FOREACH_CALLBACK_INVOKE(&data, check_id_super, cb_flag)
 
-	if (id->override) {
-		CALLBACK_INVOKE_ID(id->override->reference, IDWALK_CB_USER);
+	if (id->override != NULL) {
+		CALLBACK_INVOKE_ID(id->override->reference, IDWALK_CB_USER | IDWALK_CB_STATIC_OVERRIDE_REFERENCE);
 	}
 
 	for (; id != NULL; id = (flag & IDWALK_RECURSE) ? BLI_LINKSTACK_POP(data.ids_todo) : NULL) {
diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c
index 7e67446ca32..f900f3556af 100644
--- a/source/blender/blenkernel/intern/library_remap.c
+++ b/source/blender/blenkernel/intern/library_remap.c
@@ -174,6 +174,7 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
 	}
 
 	if (*id_p && (*id_p == old_id)) {
+		const bool is_reference = (cb_flag & IDWALK_CB_STATIC_OVERRIDE_REFERENCE) != 0;
 		const bool is_indirect = (cb_flag & IDWALK_CB_INDIRECT_USAGE) != 0;
 		const bool skip_indirect = (id_remap_data->flag & ID_REMAP_SKIP_INDIRECT_USAGE) != 0;
 		/* Note: proxy usage implies LIB_TAG_EXTERN, so on this aspect it is direct,
@@ -184,6 +185,7 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
 		const bool is_obj_editmode = (is_obj && BKE_object_is_in_editmode((Object *)id));
 		const bool is_never_null = ((cb_flag & IDWALK_CB_NEVER_NULL) && (new_id == NULL) &&
 		                            (id_remap_data->flag & ID_REMAP_FORCE_NEVER_NULL_USAGE) == 0);
+		const bool skip_reference = (id_remap_data->flag & ID_REMAP_SKIP_STATIC_OVERRIDE) != 0;
 		const bool skip_never_null = (id_remap_data->flag & ID_REMAP_SKIP_NEVER_NULL_USAGE) != 0;
 
 #ifdef DEBUG_PRINT
@@ -198,7 +200,8 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
 		/* Special hack in case it's Object->data and we are in edit mode (skipped_direct too). */
 		if ((is_never_null && skip_never_null) ||
 		    (is_obj_editmode && (((Object *)id)->data == *id_p)) ||
-		    (skip_indirect && is_indirect))
+		    (skip_indirect && is_indirect) ||
+		    (is_reference && skip_reference))
 		{
 			if (is_indirect) {
 				id_remap_data->skipped_indirect++;
@@ -211,7 +214,7 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
 					}
 				}
 			}
-			else if (is_never_null || is_obj_editmode) {
+			else if (is_never_null || is_obj_editmode || is_reference) {
 				id_remap_data->skipped_direct++;
 			}
 			else {



More information about the Bf-blender-cvs mailing list