Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/lib_id.c
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_lib_remap.h" | #include "BKE_lib_remap.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_main_namemap.h" | #include "BKE_main_namemap.h" | ||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "BKE_rigidbody.h" | #include "BKE_rigidbody.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_build.h" | #include "DEG_depsgraph_build.h" | ||||
| #include "DEG_depsgraph_query.h" | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "BLO_read_write.h" | #include "BLO_read_write.h" | ||||
| #include "atomic_ops.h" | #include "atomic_ops.h" | ||||
| //#define DEBUG_TIME | //#define DEBUG_TIME | ||||
| ▲ Show 20 Lines • Show All 643 Lines • ▼ Show 20 Lines | |||||
| * \note Most internal ID data itself is not swapped (only IDProperties are). | * \note Most internal ID data itself is not swapped (only IDProperties are). | ||||
| */ | */ | ||||
| static void id_swap(Main *bmain, ID *id_a, ID *id_b, const bool do_full_id) | 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)); | BLI_assert(GS(id_a->name) == GS(id_b->name)); | ||||
| const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id_a); | const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id_a); | ||||
| BLI_assert(id_type != NULL); | BLI_assert(id_type != NULL); | ||||
| const size_t id_struct_size = id_type->struct_size; | const size_t id_struct_size = id_type->struct_size; | ||||
mont29: ID, | |||||
Not Done Inline Actionsthat the mont29: that the | |||||
Not Done Inline Actionswith a mont29: with a | |||||
Not Done Inline Actionswhich implies that the user count of the original ID is increased mont29: which implies that the user count of the original ID is increased | |||||
| const ID id_a_back = *id_a; | const ID id_a_back = *id_a; | ||||
| const ID id_b_back = *id_b; | const ID id_b_back = *id_b; | ||||
| char *id_swap_buff = alloca(id_struct_size); | char *id_swap_buff = alloca(id_struct_size); | ||||
| memcpy(id_swap_buff, id_a, id_struct_size); | memcpy(id_swap_buff, id_a, id_struct_size); | ||||
Not Done Inline ActionsThis should ONLY happen when (cb_data->cb_flag & IDWALK_CB_USER) != 0. We have a lot of ID usages that are not refcounting. mont29: This should ONLY happen when `(cb_data->cb_flag & IDWALK_CB_USER) != 0`. We have a lot of ID… | |||||
| memcpy(id_a, id_b, id_struct_size); | memcpy(id_a, id_b, id_struct_size); | ||||
| memcpy(id_b, id_swap_buff, id_struct_size); | memcpy(id_b, id_swap_buff, id_struct_size); | ||||
| if (!do_full_id) { | if (!do_full_id) { | ||||
| /* Restore original ID's internal data. */ | /* Restore original ID's internal data. */ | ||||
| *id_a = id_a_back; | *id_a = id_a_back; | ||||
| *id_b = id_b_back; | *id_b = id_b_back; | ||||
| /* Exception: IDProperties. */ | /* Exception: IDProperties. */ | ||||
| id_a->properties = id_b_back.properties; | id_a->properties = id_b_back.properties; | ||||
| id_b->properties = id_a_back.properties; | id_b->properties = id_a_back.properties; | ||||
| /* Exception: recalc flags. */ | /* Exception: recalc flags. */ | ||||
| id_a->recalc = id_b_back.recalc; | id_a->recalc = id_b_back.recalc; | ||||
| id_b->recalc = id_a_back.recalc; | id_b->recalc = id_a_back.recalc; | ||||
| } | } | ||||
| if (bmain != NULL) { | if (bmain != NULL) { | ||||
| /* Swap will have broken internal references to itself, restore them. */ | /* 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_a, id_b, id_a, ID_REMAP_SKIP_NEVER_NULL_USAGE); | ||||
Not Done Inline ActionsAre you sure about that? It means that you are not handling pointers within embedded IDs, which will therefore still potentially point to evaluated/non-Main IDs? mont29: Are you sure about that? It means that you are not handling pointers within embedded IDs, which… | |||||
Done Inline ActionsNo, I'm not, I've misread the comment. Good catch! sergey: No, I'm not, I've misread the comment. Good catch! | |||||
| BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, ID_REMAP_SKIP_NEVER_NULL_USAGE); | BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, ID_REMAP_SKIP_NEVER_NULL_USAGE); | ||||
| } | } | ||||
Not Done Inline Actionsbut it -> but brecht: but it -> but | |||||
Not Done Inline Actions'evaluated ID', or 'evaluated object data', not 'evaluated object', object itself has no shapekey, and calling BKE_key_from_id_p on an Object ID will always return NULL... mont29: 'evaluated ID', or 'evaluated object data', not 'evaluated object', object itself has no… | |||||
| } | } | ||||
| void BKE_lib_id_swap(Main *bmain, ID *id_a, ID *id_b) | void BKE_lib_id_swap(Main *bmain, ID *id_a, ID *id_b) | ||||
| { | { | ||||
| id_swap(bmain, id_a, id_b, false); | id_swap(bmain, id_a, id_b, false); | ||||
| } | } | ||||
| void BKE_lib_id_swap_full(Main *bmain, ID *id_a, ID *id_b) | void BKE_lib_id_swap_full(Main *bmain, ID *id_a, ID *id_b) | ||||
| ▲ Show 20 Lines • Show All 1,276 Lines • ▼ Show 20 Lines | LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &id->override_library->properties) { | ||||
| } | } | ||||
| if (opop->subitem_local_name) { | if (opop->subitem_local_name) { | ||||
| BLO_write_string(writer, opop->subitem_local_name); | BLO_write_string(writer, opop->subitem_local_name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static int foreach_assign_id_to_orig_callback(LibraryIDLinkCallbackData *cb_data) | |||||
| { | |||||
| ID **id_p = cb_data->id_pointer; | |||||
| if (*id_p) { | |||||
| *id_p = DEG_get_original_id(*id_p); | |||||
| } | |||||
| return IDWALK_RET_NOP; | |||||
| } | |||||
| void BKE_id_assign_directly_used_ids_to_original(ID *id) | |||||
| { | |||||
| BKE_library_foreach_ID_link( | |||||
| NULL, id, foreach_assign_id_to_orig_callback, NULL, IDWALK_IGNORE_EMBEDDED_ID); | |||||
| } | |||||
| No newline at end of file | |||||
ID,