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 633 Lines • ▼ Show 20 Lines | if (key_new != NULL) { | ||||
| BKE_animdata_duplicate_id_action(bmain, key_new, duplicate_flags); | BKE_animdata_duplicate_id_action(bmain, key_new, duplicate_flags); | ||||
| } | } | ||||
| /* Note that actions of embedded data (root nodetrees and master collections) are handled | /* Note that actions of embedded data (root nodetrees and master collections) are handled | ||||
| * by `BKE_animdata_duplicate_id_action` as well. */ | * by `BKE_animdata_duplicate_id_action` as well. */ | ||||
| } | } | ||||
| return id->newid; | return id->newid; | ||||
| } | } | ||||
| static int foreach_assign_id_to_orig_callback(LibraryIDLinkCallbackData *cb_data) | |||||
| { | |||||
| ID **id_p = cb_data->id_pointer; | |||||
| if (*id_p) { | |||||
| ID *id = *id_p; | |||||
| *id_p = DEG_get_original_id(id); | |||||
| /* If the ID changes increase the user count. | |||||
| * | |||||
| * This means that reference to evaluated ID has been changed with reference to the original IR | |||||
mont29: ID, | |||||
Not Done Inline Actionsthat the mont29: that the | |||||
Not Done Inline Actionswith a mont29: with a | |||||
| * which implies the user counter of the original ID increased. | |||||
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 | |||||
| * | |||||
| * The evaluated IDs do not maintain their user counter, so do not change it to avoid issues | |||||
| * with the user counter going negative. */ | |||||
| if (*id_p != id) { | |||||
| id_us_plus(*id_p); | |||||
| } | |||||
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… | |||||
| } | |||||
| return IDWALK_RET_NOP; | |||||
| } | |||||
| ID *BKE_id_copy_for_use_in_bmain(Main *bmain, const ID *id) | |||||
| { | |||||
| ID *newid = BKE_id_copy(bmain, id); | |||||
| if (newid == NULL) { | |||||
| return newid; | |||||
| } | |||||
| /* Assign ID references directly used by the given ID to their original complementary parts. | |||||
| * | |||||
| * For example, when is called on an evaluated object will assign object->data to its original | |||||
| * pointer, the evaluated object->data will be kept unchanged. */ | |||||
| BKE_library_foreach_ID_link( | |||||
| NULL, newid, foreach_assign_id_to_orig_callback, NULL, IDWALK_IGNORE_EMBEDDED_ID); | |||||
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! | |||||
| /* Shape keys reference on evaluated object is preserved to keep driver paths available, but it | |||||
brechtUnsubmitted 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… | |||||
| * the key data is likely to be invalid now due to modifiers, so clear the shape key reference | |||||
| * avoiding any possible shape corruption. */ | |||||
| if (DEG_is_evaluated_id(id)) { | |||||
| Key **key_p = BKE_key_from_id_p(newid); | |||||
| if (key_p) { | |||||
| *key_p = NULL; | |||||
| } | |||||
| } | |||||
| return newid; | |||||
| } | |||||
| /** | /** | ||||
| * Does a mere memory swap over the whole IDs data (including type-specific memory). | * 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). | * \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)); | ||||
| ▲ Show 20 Lines • Show All 1,323 Lines • Show Last 20 Lines | |||||
ID,