[Bf-blender-cvs] [5d58b7f0739] master: Fix T61660: Wrong user counter on curves with shared material.

Bastien Montagne noreply at git.blender.org
Mon Feb 18 15:27:41 CET 2019


Commit: 5d58b7f073987543d8d952587a8ffd1268ca443e
Author: Bastien Montagne
Date:   Mon Feb 18 15:24:23 2019 +0100
Branches: master
https://developer.blender.org/rB5d58b7f073987543d8d952587a8ffd1268ca443e

Fix T61660: Wrong user counter on curves with shared material.

Patch by @sergey.

Note that this is really a bad thing actually, ideally we should never
get that situation (IDs in Main referencing temp IDs outside of it).
That can lead to many possible similar cases...

Fixing that is not trivial though, so for now we'll have to live with
it, until we have migrated *all* of our temp datablocks generation
outside of Main's.

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

M	source/blender/blenkernel/intern/library_remap.c

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

diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c
index 92b3e581fa5..93ea5c35213 100644
--- a/source/blender/blenkernel/intern/library_remap.c
+++ b/source/blender/blenkernel/intern/library_remap.c
@@ -245,10 +245,19 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
 				                     ID_RECALC_COPY_ON_WRITE | ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
 			}
 			if (cb_flag & IDWALK_CB_USER) {
-				id_us_min(old_id);
-				/* We do not want to handle LIB_TAG_INDIRECT/LIB_TAG_EXTERN here. */
-				if (new_id)
+				/* NOTE: We don't user-count IDs which are not in the main database.
+				 * This is because in certain conditions we can have datablocks in
+				 * the main which are referencing datablocks 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) {
+					id_us_min(old_id);
+				}
+				if (new_id != NULL && (new_id->tag & LIB_TAG_NO_MAIN) == 0) {
+					/* We do not want to handle LIB_TAG_INDIRECT/LIB_TAG_EXTERN here. */
 					new_id->us++;
+				}
 			}
 			else if (cb_flag & IDWALK_CB_USER_ONE) {
 				id_us_ensure_real(new_id);



More information about the Bf-blender-cvs mailing list