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.
This commit is contained in:
Bastien Montagne 2016-06-27 15:43:04 +02:00
parent 34024c7cd8
commit e2c7ee7733
Notes: blender-bot 2023-02-14 07:47:54 +01:00
Referenced by issue #48740, material remapping work properly only the first time
2 changed files with 13 additions and 5 deletions

View File

@ -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 {

View File

@ -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);