Commit: e2c7ee773311734450a229051673fbfea61b641a
Author: Bastien Montagne
Date:   Mon Jun 27 15:43:04 2016 +0200
Branches: master
https://developer.blender.org/rBe2c7ee773311734450a229051673fbfea61b641a

Fix T48740: User could remap indirect libdata usages from outliner.

Remapping indirect usage of IDs is forbidden from user space, this is calling 
for
nice nightmare with libraries handling (and undo crash, among other things).

Not sure why I was 'laxist' about indirect usage cases detection like that,
for now just consider any ID used by another linked datablock as indirect usage 
case!

Also, added some error/warning reports to Outliner's remap code.

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

M       source/blender/blenkernel/intern/library_remap.c
M       source/blender/editors/space_outliner/outliner_edit.c

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

diff --git a/source/blender/blenkernel/intern/library_remap.c 
b/source/blender/blenkernel/intern/library_remap.c
index 4bde075..f08315b 100644
--- a/source/blender/blenkernel/intern/library_remap.c
+++ b/source/blender/blenkernel/intern/library_remap.c
@@ -163,15 +163,14 @@ static int foreach_libblock_remap_callback(void 
*user_data, ID *UNUSED(id_self),
        }
 
        if (*id_p && (*id_p == old_id)) {
+               const bool is_indirect = (id->lib != NULL);
+               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,
                 *       on the other hand since they get reset to lib data on 
file open/reload it is indirect too...
                 *       Edit Mode is also a 'skip direct' case. */
                const bool is_obj = (GS(id->name) == ID_OB);
                const bool is_proxy = (is_obj && (((Object *)id)->proxy || 
((Object *)id)->proxy_group));
                const bool is_obj_editmode = (is_obj && 
BKE_object_is_in_editmode((Object *)id));
-               /* Note that indirect data from same file as processed ID is 
**not** considered indirect! */
-               const bool is_indirect = ((id->lib != NULL) && (id->lib != 
old_id->lib));
-               const bool skip_indirect = (id_remap_data->flag & 
ID_REMAP_SKIP_INDIRECT_USAGE) != 0;
                const bool is_never_null = ((cb_flag & IDWALK_NEVER_NULL) && 
(new_id == NULL) &&
                                            (id_remap_data->flag & 
ID_REMAP_FORCE_NEVER_NULL_USAGE) == 0);
                const bool skip_never_null = (id_remap_data->flag & 
ID_REMAP_SKIP_NEVER_NULL_USAGE) != 0;
@@ -185,7 +184,7 @@ static int foreach_libblock_remap_callback(void *user_data, 
ID *UNUSED(id_self),
                    (is_obj_editmode && (((Object *)id)->data == *id_p)) ||
                    (skip_indirect && (is_proxy || is_indirect)))
                {
-                       if (is_never_null || is_proxy || is_obj_editmode) {
+                       if (!is_indirect && (is_never_null || is_proxy || 
is_obj_editmode)) {
                                id_remap_data->skipped_direct++;
                        }
                        else {
diff --git a/source/blender/editors/space_outliner/outliner_edit.c 
b/source/blender/editors/space_outliner/outliner_edit.c
index 687869a..57d9ff7 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -399,13 +399,22 @@ static int outliner_id_remap_exec(bContext *C, wmOperator 
*op)
        ID *new_id = BLI_findlink(which_libbase(CTX_data_main(C), id_type), 
RNA_enum_get(op->ptr, "new_id"));
 
        /* check for invalid states */
-       if (soops == NULL)
+       if (soops == NULL) {
                return OPERATOR_CANCELLED;
+       }
 
        if (!(old_id && (old_id != new_id) && (GS(old_id->name) == 
GS(new_id->name)))) {
+               BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT, "Invalid 
old/new ID pair ('%s' / '%s')",
+                           old_id->name, new_id->name);
                return OPERATOR_CANCELLED;
        }
 
+       if (old_id->lib) {
+               BKE_reportf(op->reports, RPT_WARNING,
+                           "Old ID '%s' is linked from a library, indirect 
usages of this datablock will not be remapped",
+                           old_id->name);
+       }
+
        BKE_libblock_remap(bmain, old_id, new_id,
                                           ID_REMAP_SKIP_INDIRECT_USAGE | 
ID_REMAP_SKIP_NEVER_NULL_USAGE);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to