[Bf-blender-cvs] [263f6149328] blender2.8: Add dedicated pointer to an original ID datablock

Sergey Sharybin noreply at git.blender.org
Tue Jan 16 15:09:56 CET 2018


Commit: 263f61493286cbcfb8ee6b86979d50794e358128
Author: Sergey Sharybin
Date:   Tue Jan 16 14:57:02 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB263f61493286cbcfb8ee6b86979d50794e358128

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.

===================================================================

M	source/blender/blenloader/intern/readfile.c
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.h
M	source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
M	source/blender/makesdna/DNA_ID.h

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index bf2cc91c328..34d93620f14 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -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) {
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
index c9bdd194227..cc8ad08ea3b 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
@@ -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;
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
index abd17616584..ff447b53b1e 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
@@ -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)
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 04929931bfd..fd8cd8b2855 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -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;



More information about the Bf-blender-cvs mailing list