Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey@blender.org>2022-03-23 14:05:47 +0300
committerSergey Sharybin <sergey@blender.org>2022-03-25 13:45:50 +0300
commit03df72ee4e7e7f9893df73de426cdc3af1c7a676 (patch)
tree2444ca325586511411f7b1f48e9c59887f30c9fe /source/blender/blenkernel
parent75b8c4fc18997851620f4abd491f7c418f6666ee (diff)
Implement C++ methods for DNA structures
This change makes it possible to add implementation of common C++ methods for DNA structures which helps ensuring unsafe operations like shallow copy are done explicitly. For example, creating a shallow copy used to be: Object temp_object = *input_object; In the C++ context it was seen like the temp_object is properly decoupled from the input object, while in the reality is it not. Now this code becomes: Object temp_object = blender::dna::shallow_copy(*input_object); The copy and move constructor and assignment operators are now explicitly disabled. Other than a more explicit resource management this change also solves a lot of warnings generated by the implicitly defined copy constructors w.r.t dealing with deprecated fields. These warnings were generated by Apple Clang when a shallow object copy was created via implicitly defined copy constructor. In order to enable C++ methods for DNA structures a newly added macro `DNA_DEFINE_CXX_METHODS()` is to be used: tpyedef struct Object { DNA_DEFINE_CXX_METHODS(Object) ... } Object; For the shallow copy use `blender::dna::shallow_copy()`. The implementation of the memcpy is hidden via an internal DNA function to avoid pulling `string.h` into every DNA header. This means that the solution does not affect on the headers dependencies. --- Ideally `DNA_shallow_copy` would be defined in a more explicit header, but don;t think we have a suitable one already. Maybe we can introduce `DNA_access.h` ? Differential Revision: https://developer.blender.org/D14427
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/intern/mesh_convert.cc6
-rw-r--r--source/blender/blenkernel/intern/object.cc2
2 files changed, 5 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc
index 40c6fbcf67e..1be2d06ce61 100644
--- a/source/blender/blenkernel/intern/mesh_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_convert.cc
@@ -910,7 +910,8 @@ static void curve_to_mesh_eval_ensure(Object &object)
*
* So we create temporary copy of the object which will use same data as the original bevel, but
* will have no modifiers. */
- Object bevel_object = {{nullptr}};
+ Object bevel_object;
+ memset(&bevel_object, 0, sizeof(bevel_object));
if (curve.bevobj != nullptr) {
memcpy(&bevel_object, curve.bevobj, sizeof(bevel_object));
BLI_listbase_clear(&bevel_object.modifiers);
@@ -919,7 +920,8 @@ static void curve_to_mesh_eval_ensure(Object &object)
}
/* Same thing for taper. */
- Object taper_object = {{nullptr}};
+ Object taper_object;
+ memset(&taper_object, 0, sizeof(taper_object));
if (curve.taperobj != nullptr) {
memcpy(&taper_object, curve.taperobj, sizeof(taper_object));
BLI_listbase_clear(&taper_object.modifiers);
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 1e3b5d77fa7..6d1eac5af49 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -3946,7 +3946,7 @@ bool BKE_object_minmax_dupli(Depsgraph *depsgraph,
/* pass */
}
else {
- Object temp_ob = *dob->ob;
+ Object temp_ob = blender::dna::shallow_copy(*dob->ob);
/* Do not modify the original boundbox. */
temp_ob.runtime.bb = nullptr;
BKE_object_replace_data_on_shallow_copy(&temp_ob, dob->ob_data);