[Bf-blender-cvs] [d4e67df] object_nodes: Fix for store/load of mesh_ptr on the stack.

Lukas Tönne noreply at git.blender.org
Tue Nov 24 09:45:02 CET 2015


Commit: d4e67dfe377ff8caff749d1f06d94803fe0c6ef6
Author: Lukas Tönne
Date:   Mon Nov 23 12:29:18 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBd4e67dfe377ff8caff749d1f06d94803fe0c6ef6

Fix for store/load of mesh_ptr on the stack.

Most actual mesh operations should only store the data pointer itself
but not modify the refcount.

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

M	source/blender/blenvm/bvm/bvm_eval.cc
M	source/blender/blenvm/bvm/bvm_eval_common.h
M	source/blender/blenvm/bvm/bvm_eval_mesh.h

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

diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index c2ac111..ebf424a 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -96,7 +96,7 @@ static void eval_op_value_pointer(float *stack, PointerRNA value, StackIndex off
  */
 static void eval_op_value_mesh(float *stack, StackIndex offset)
 {
-	stack_store_mesh(stack, offset, __empty_mesh__);
+	stack_store_mesh_ptr(stack, offset, __empty_mesh__);
 }
 
 static void eval_op_float_to_int(float *stack, StackIndex offset_from, StackIndex offset_to)
@@ -169,14 +169,14 @@ static void eval_op_init_mesh_ptr(float *stack, StackIndex offset, int use_count
 {
 	mesh_ptr p(NULL);
 	p.set_use_count(use_count);
-	stack_store_mesh(stack, offset, p);
+	stack_store_mesh_ptr(stack, offset, p);
 }
 
 static void eval_op_release_mesh_ptr(float *stack, StackIndex offset)
 {
-	mesh_ptr p = stack_load_mesh(stack, offset);
+	mesh_ptr p = stack_load_mesh_ptr(stack, offset);
 	p.decrement_use_count();
-	stack_store_mesh(stack, offset, p);
+	stack_store_mesh_ptr(stack, offset, p);
 }
 
 static void eval_op_point_position(const EvalData *data, float *stack, StackIndex offset)
diff --git a/source/blender/blenvm/bvm/bvm_eval_common.h b/source/blender/blenvm/bvm/bvm_eval_common.h
index f7507a0..f07ef31 100644
--- a/source/blender/blenvm/bvm/bvm_eval_common.h
+++ b/source/blender/blenvm/bvm/bvm_eval_common.h
@@ -67,11 +67,16 @@ inline static PointerRNA stack_load_pointer(float *stack, StackIndex offset)
 	return *(PointerRNA *)(&stack[offset]);
 }
 
-inline static mesh_ptr stack_load_mesh(float *stack, StackIndex offset)
+inline static mesh_ptr stack_load_mesh_ptr(float *stack, StackIndex offset)
 {
 	return *(mesh_ptr *)(&stack[offset]);
 }
 
+inline static DerivedMesh *stack_load_mesh(float *stack, StackIndex offset)
+{
+	return ((mesh_ptr *)(&stack[offset]))->get();
+}
+
 inline static void stack_store_float(float *stack, StackIndex offset, float f)
 {
 	*(float *)(&stack[offset]) = f;
@@ -102,11 +107,16 @@ inline static void stack_store_pointer(float *stack, StackIndex offset, PointerR
 	*(PointerRNA *)(&stack[offset]) = p;
 }
 
-inline static void stack_store_mesh(float *stack, StackIndex offset, mesh_ptr p)
+inline static void stack_store_mesh_ptr(float *stack, StackIndex offset, mesh_ptr p)
 {
 	*(mesh_ptr *)(&stack[offset]) = p;
 }
 
+inline static void stack_store_mesh(float *stack, StackIndex offset, DerivedMesh *dm)
+{
+	((mesh_ptr *)(&stack[offset]))->set(dm);
+}
+
 } /* namespace bvm */
 
 #endif /* __BVM_EVAL_COMMON_H__ */
diff --git a/source/blender/blenvm/bvm/bvm_eval_mesh.h b/source/blender/blenvm/bvm/bvm_eval_mesh.h
index 5c9e4fb..c930861 100644
--- a/source/blender/blenvm/bvm/bvm_eval_mesh.h
+++ b/source/blender/blenvm/bvm/bvm_eval_mesh.h
@@ -42,10 +42,8 @@ namespace bvm {
 
 static void eval_op_mesh_load(const EvalData *data, float *stack, StackIndex offset)
 {
-	mesh_ptr p = stack_load_mesh(stack, offset);
 	DerivedMesh *dm = CDDM_from_mesh(data->modifier.base_mesh);
-	p.set(dm);
-	stack_store_mesh(stack, offset, p);
+	stack_store_mesh(stack, offset, dm);
 }
 
 static DerivedMesh *do_array(DerivedMesh *dm, int count, const matrix44 &tfm)
@@ -154,14 +152,14 @@ static DerivedMesh *do_array(DerivedMesh *dm, int count, const matrix44 &tfm)
 static void eval_op_mesh_array(float *stack, StackIndex offset_mesh_in, StackIndex offset_mesh_out,
                                StackIndex offset_count, StackIndex offset_transform)
 {
-	DerivedMesh *dm = stack_load_mesh(stack, offset_mesh_in).get();
+	DerivedMesh *dm = stack_load_mesh(stack, offset_mesh_in);
 	int count = stack_load_int(stack, offset_count);
 	CLAMP_MIN(count, 0);
 	matrix44 tfm = stack_load_matrix44(stack, offset_transform);
 	
 	DerivedMesh *result = do_array(dm, count, tfm);
 	
-	stack_store_mesh(stack, offset_mesh_out, mesh_ptr(result));
+	stack_store_mesh(stack, offset_mesh_out, result);
 }
 
 } /* namespace bvm */




More information about the Bf-blender-cvs mailing list