diff options
-rw-r--r-- | source/blender/blenkernel/BKE_lib_id.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_id.c | 48 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_override.c | 2 |
3 files changed, 43 insertions, 12 deletions
diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h index 27dd1e637f3..25ccc5bd5b6 100644 --- a/source/blender/blenkernel/BKE_lib_id.h +++ b/source/blender/blenkernel/BKE_lib_id.h @@ -217,7 +217,10 @@ bool id_single_user(struct bContext *C, bool BKE_id_copy_is_allowed(const struct ID *id); bool BKE_id_copy(struct Main *bmain, const struct ID *id, struct ID **newid); bool BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag); -void BKE_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b); + +void BKE_lib_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b); +void BKE_lib_id_swap_full(struct Main *bmain, struct ID *id_a, struct ID *id_b); + void id_sort_by_name(struct ListBase *lb, struct ID *id, struct ID *id_sorting_hint); void BKE_lib_id_expand_local(struct Main *bmain, struct ID *id); diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 27d4b8dd047..1ae53f5a85d 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -597,7 +597,7 @@ bool BKE_id_copy(Main *bmain, const ID *id, ID **newid) * Does a mere memory swap over the whole IDs data (including type-specific memory). * \note Most internal ID data itself is not swapped (only IDProperties are). */ -void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b) +static void id_swap(Main *bmain, ID *id_a, ID *id_b, const bool do_full_id) { BLI_assert(GS(id_a->name) == GS(id_b->name)); @@ -651,17 +651,45 @@ void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b) #undef CASE_SWAP - /* Restore original ID's internal data. */ - *id_a = id_a_back; - *id_b = id_b_back; + if (!do_full_id) { + /* Restore original ID's internal data. */ + *id_a = id_a_back; + *id_b = id_b_back; - /* Exception: IDProperties. */ - id_a->properties = id_b_back.properties; - id_b->properties = id_a_back.properties; + /* Exception: IDProperties. */ + id_a->properties = id_b_back.properties; + id_b->properties = id_a_back.properties; + } - /* Swap will have broken internal references to itself, restore them. */ - BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, ID_REMAP_SKIP_NEVER_NULL_USAGE); - BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, ID_REMAP_SKIP_NEVER_NULL_USAGE); + if (bmain != NULL) { + /* Swap will have broken internal references to itself, restore them. */ + BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, ID_REMAP_SKIP_NEVER_NULL_USAGE); + BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, ID_REMAP_SKIP_NEVER_NULL_USAGE); + } +} + +/** + * Does a mere memory swap over the whole IDs data (including type-specific memory). + * \note Most internal ID data itself is not swapped (only IDProperties are). + * + * \param bmain May be NULL, in which case there will be no remapping of internal pointers to + * itself. + */ +void BKE_lib_id_swap(Main *bmain, ID *id_a, ID *id_b) +{ + id_swap(bmain, id_a, id_b, false); +} + +/** + * Does a mere memory swap over the whole IDs data (including type-specific memory). + * \note All internal ID data itself is also swapped. + * + * \param bmain May be NULL, in which case there will be no remapping of internal pointers to + * itself. + */ +void BKE_lib_id_swap_full(Main *bmain, ID *id_a, ID *id_b) +{ + id_swap(bmain, id_a, id_b, true); } /** Does *not* set ID->newid pointer. */ diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c index af861b5b0e9..81f7e158b40 100644 --- a/source/blender/blenkernel/intern/lib_override.c +++ b/source/blender/blenkernel/intern/lib_override.c @@ -813,7 +813,7 @@ void BKE_lib_override_library_update(Main *bmain, ID *local) /* This also transfers all pointers (memory) owned by local to tmp_id, and vice-versa. * So when we'll free tmp_id, we'll actually free old, outdated data from local. */ - BKE_id_swap(bmain, local, tmp_id); + BKE_lib_id_swap(bmain, local, tmp_id); /* Again, horribly inn-efficient in our case, we need something off-Main * (aka more generic nolib copy/free stuff)! */ |