Core: IDRemapp: Allow remapping mismatching ID types.
While this should not be allowed in most cases, in some (e.g.conversion between different ID types), this is actually a valid operation.
This commit is contained in:
@@ -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<ID *> 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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user