[Bf-blender-cvs] [dada265] alembic: Alembic: Fix crash of viewport render with strands read from alembic cache

Sergey Sharybin noreply at git.blender.org
Wed Apr 22 13:07:49 CEST 2015


Commit: dada265e2f5213bc948943b1ea8dcfc076703374
Author: Sergey Sharybin
Date:   Wed Apr 22 15:37:46 2015 +0500
Branches: alembic
https://developer.blender.org/rBdada265e2f5213bc948943b1ea8dcfc076703374

Alembic: Fix crash of viewport render with strands read from alembic cache

The issue was caused by RNA passing ownership from the cache data used by Blender
to Cycles. This lead to situations when all of a sudden blender looses data it
was expecting to have.

Now instead of passing ownership we're just copying strands from the data, so both
Blender and Cycles are having it's own local data.

Ideally this data will be shared between viewport and Cycles, but that's a bit
more tricky to do without modifying RNA API. Would happen eventually tho.

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

M	source/blender/blenkernel/BKE_strands.h
M	source/blender/blenkernel/intern/strands.c
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index daee2f9..3046714 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -24,6 +24,7 @@
 #include "DNA_strands_types.h"
 
 struct Strands *BKE_strands_new(int strands, int verts);
+struct Strands *BKE_strands_copy(struct Strands *strands);
 void BKE_strands_free(struct Strands *strands);
 
 void BKE_strands_add_motion_state(struct Strands *strands);
@@ -37,6 +38,7 @@ void BKE_strands_get_minmax(struct Strands *strands, float min[3], float max[3],
 
 
 struct StrandsChildren *BKE_strands_children_new(int strands, int verts);
+struct StrandsChildren *BKE_strands_children_copy(struct StrandsChildren *strands);
 void BKE_strands_children_free(struct StrandsChildren *strands);
 
 void BKE_strands_children_deform(struct StrandsChildren *strands, struct Strands *parents, bool use_motion);
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 313b03f9..b29225c 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -39,6 +39,18 @@ Strands *BKE_strands_new(int curves, int verts)
 	return strands;
 }
 
+Strands *BKE_strands_copy(Strands *strands)
+{
+	Strands *new_strands = MEM_dupallocN(strands);
+	if (new_strands->curves)
+		new_strands->curves = MEM_dupallocN(new_strands->curves);
+	if (new_strands->verts)
+		new_strands->verts = MEM_dupallocN(new_strands->verts);
+	if (new_strands->state)
+		new_strands->state = MEM_dupallocN(new_strands->state);
+	return new_strands;
+}
+
 void BKE_strands_free(Strands *strands)
 {
 	if (strands) {
@@ -170,6 +182,16 @@ StrandsChildren *BKE_strands_children_new(int curves, int verts)
 	return strands;
 }
 
+StrandsChildren *BKE_strands_children_copy(StrandsChildren *strands)
+{
+	StrandsChildren *new_strands = MEM_dupallocN(strands);
+	if (new_strands->curves)
+		new_strands->curves = MEM_dupallocN(new_strands->curves);
+	if (new_strands->verts)
+		new_strands->verts = MEM_dupallocN(new_strands->verts);
+	return new_strands;
+}
+
 void BKE_strands_children_free(StrandsChildren *strands)
 {
 	if (strands) {
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 2fe07ef..ea89552 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1545,7 +1545,12 @@ Strands *rna_DupliObject_strands_new(DupliObject *dob, ReportList *UNUSED(report
 			data = BKE_dupli_cache_find_data(parent->dup_cache, dob->ob);
 			if (data) {
 				strands = BKE_dupli_object_data_find_strands(data, psys->name);
-				BKE_dupli_object_data_acquire_strands(data, strands);
+				/* TODO(sergey): Consider sharing the data between viewport and
+				 * render engine.
+				 */
+				if (strands != NULL) {
+					strands = BKE_strands_copy(strands);
+				}
 			}
 		}
 		else {
@@ -1595,7 +1600,12 @@ StrandsChildren *rna_DupliObject_strands_children_new(DupliObject *dob, ReportLi
 			data = BKE_dupli_cache_find_data(parent->dup_cache, dob->ob);
 			if (data) {
 				strands = BKE_dupli_object_data_find_strands_children(data, psys->name);
-				BKE_dupli_object_data_acquire_strands_children(data, strands);
+				/* TODO(sergey): Consider sharing the data between viewport and
+				 * render engine.
+				 */
+				if (strands != NULL) {
+					strands = BKE_strands_children_copy(strands);
+				}
 			}
 		}
 		else {




More information about the Bf-blender-cvs mailing list