Add dedicated pointer to an original ID datablock
Before we were re-using newid pointer inside of ID structure where we were storing pointer to an original datablock. It seems there is no way we can avoid requirement of having pointer to an original datablock, so let's stop obusing system which was only designed to be a runtime only thingie. Will be more safe this way, without need to worry about using any API which modifies newid.
This commit is contained in:
@@ -8521,6 +8521,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
|
||||
id->us = ID_FAKE_USERS(id);
|
||||
id->icon_id = 0;
|
||||
id->newid = NULL; /* Needed because .blend may have been saved with crap value here... */
|
||||
id->orig_id = NULL;
|
||||
|
||||
/* this case cannot be direct_linked: it's just the ID part */
|
||||
if (bhead->code == ID_ID) {
|
||||
|
||||
@@ -102,7 +102,7 @@ struct DepsgraphNodeBuilder {
|
||||
template<typename T>
|
||||
T *get_orig_datablock(const T *cow) const {
|
||||
if (DEG_depsgraph_use_copy_on_write()) {
|
||||
return (T *)cow->id.newid;
|
||||
return (T *)cow->id.orig_id;
|
||||
}
|
||||
else {
|
||||
return (T *)cow;
|
||||
|
||||
@@ -781,7 +781,7 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
|
||||
*/
|
||||
if (mesh_evaluated != NULL) {
|
||||
if (object->data == mesh_evaluated) {
|
||||
object->data = mesh_evaluated->id.newid;
|
||||
object->data = mesh_evaluated->id.orig_id;
|
||||
}
|
||||
}
|
||||
/* Make a backup of base flags. */
|
||||
@@ -817,7 +817,7 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
|
||||
* pointers are left behind.
|
||||
*/
|
||||
mesh_evaluated->edit_btmesh =
|
||||
((Mesh *)mesh_evaluated->id.newid)->edit_btmesh;
|
||||
((Mesh *)mesh_evaluated->id.orig_id)->edit_btmesh;
|
||||
}
|
||||
}
|
||||
if (base_collection_properties != NULL) {
|
||||
@@ -921,8 +921,7 @@ bool deg_validate_copy_on_write_datablock(ID *id_cow)
|
||||
void deg_tag_copy_on_write_id(ID *id_cow, const ID *id_orig)
|
||||
{
|
||||
id_cow->tag |= LIB_TAG_COPY_ON_WRITE;
|
||||
/* TODO(sergey): Is it safe to re-use newid for original ID link? */
|
||||
id_cow->newid = (ID *)id_orig;
|
||||
id_cow->orig_id = (ID *)id_orig;
|
||||
}
|
||||
|
||||
bool deg_copy_on_write_is_expanded(const ID *id_cow)
|
||||
|
||||
@@ -216,7 +216,11 @@ typedef struct ID {
|
||||
IDProperty *properties;
|
||||
|
||||
IDOverrideStatic *override_static; /* Reference linked ID which this one overrides. */
|
||||
void *pad1;
|
||||
|
||||
/* Only set for datablocks which are coming from copy-on-write, points to
|
||||
* the original version of it.
|
||||
*/
|
||||
void *orig_id;
|
||||
|
||||
void *py_instance;
|
||||
} ID;
|
||||
|
||||
Reference in New Issue
Block a user