diff --git a/source/blender/blenkernel/BKE_lib_remap.hh b/source/blender/blenkernel/BKE_lib_remap.hh index 6717d75021e..4586cefe8d2 100644 --- a/source/blender/blenkernel/BKE_lib_remap.hh +++ b/source/blender/blenkernel/BKE_lib_remap.hh @@ -86,6 +86,12 @@ enum { * etc.). */ ID_REMAP_DO_LIBRARY_POINTERS = 1 << 8, + /** Allow remapping of an ID opinter of a certain to another one of a different type. + * + * WARNING: Use with caution. Should only be needed in a very small amount of cases, e.g. when + * converting an ID type to another. */ + ID_REMAP_ALLOW_IDTYPE_MISMATCH = 1 << 9, + /** * Don't touch the special user counts (use when the 'old' remapped ID remains in use): * - Do not transfer 'fake user' status from old to new ID. @@ -267,6 +273,13 @@ class IDRemapper { */ blender::Set never_null_users_; + public: + /** + * In almost all cases, the original pointer and its new replacement should be of the same type. + * however, there are some rare exceptions, e.g. when converting from one ID type to another. + */ + bool allow_idtype_mismatch = false; + public: void clear(void) { diff --git a/source/blender/blenkernel/intern/lib_id_remapper.cc b/source/blender/blenkernel/intern/lib_id_remapper.cc index 7027c4d175d..b79a0783656 100644 --- a/source/blender/blenkernel/intern/lib_id_remapper.cc +++ b/source/blender/blenkernel/intern/lib_id_remapper.cc @@ -15,7 +15,8 @@ namespace blender::bke::id { void IDRemapper::add(ID *old_id, ID *new_id) { BLI_assert(old_id != nullptr); - BLI_assert(new_id == nullptr || (GS(old_id->name) == GS(new_id->name))); + BLI_assert(new_id == nullptr || this->allow_idtype_mismatch || + (GS(old_id->name) == GS(new_id->name))); BLI_assert(BKE_idtype_idcode_to_idfilter(GS(old_id->name)) != 0); mappings_.add(old_id, new_id); @@ -25,7 +26,8 @@ void IDRemapper::add(ID *old_id, ID *new_id) void IDRemapper::add_overwrite(ID *old_id, ID *new_id) { BLI_assert(old_id != nullptr); - BLI_assert(new_id == nullptr || (GS(old_id->name) == GS(new_id->name))); + BLI_assert(new_id == nullptr || this->allow_idtype_mismatch || + (GS(old_id->name) == GS(new_id->name))); BLI_assert(BKE_idtype_idcode_to_idfilter(GS(old_id->name)) != 0); mappings_.add_overwrite(old_id, new_id); diff --git a/source/blender/blenkernel/intern/lib_remap.cc b/source/blender/blenkernel/intern/lib_remap.cc index 2acc232421d..70f3dfe4b2a 100644 --- a/source/blender/blenkernel/intern/lib_remap.cc +++ b/source/blender/blenkernel/intern/lib_remap.cc @@ -569,7 +569,8 @@ static void libblock_remap_foreach_idpair_cb(ID *old_id, ID *new_id, void *user_ const int remap_flags = data->remap_flags; BLI_assert(old_id != nullptr); - BLI_assert((new_id == nullptr) || GS(old_id->name) == GS(new_id->name)); + BLI_assert((new_id == nullptr) || remap_flags & ID_REMAP_ALLOW_IDTYPE_MISMATCH || + GS(old_id->name) == GS(new_id->name)); if (free_notifier_reference_cb) { free_notifier_reference_cb(old_id);