[Bf-blender-cvs] [1ec5edc] master: Fix T50094: Crash when viewport rendering point density texture

Sergey Sharybin noreply at git.blender.org
Tue Nov 29 11:43:59 CET 2016


Commit: 1ec5edcc9669f46b1f0fd29c765a326ea525e7f3
Author: Sergey Sharybin
Date:   Tue Nov 29 11:39:14 2016 +0100
Branches: master
https://developer.blender.org/rB1ec5edcc9669f46b1f0fd29c765a326ea525e7f3

Fix T50094: Crash when viewport rendering point density texture

The idea is simple: cache PD resolution from cache_point_density() RNA
function because that one is supposed to be called while database is
locked for original synchronization.

Ideally we would also pass array size to the sampling function, but
it turned out to be quite problematic because API only accepts int type
and passing size_t might cause some weird behavior.

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

M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c

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

diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 46b30f4..3a7e2b6 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -811,7 +811,10 @@ typedef struct NodeShaderTexPointDensity {
 	short color_source;
 	short ob_color_source;
 	char vertex_attribute_name[64]; /* vertex attribute layer for color source, MAX_CUSTOMDATA_LAYER_NAME */
+	/* Used at runtime only by sampling RNA API. */
 	PointDensity pd;
+	int cached_resolution;
+	int pad2;
 } NodeShaderTexPointDensity;
 
 /* TEX_output */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 47e9d98..34002f8 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3107,6 +3107,9 @@ void rna_ShaderNodePointDensity_density_cache(bNode *self,
 		            sizeof(pd->vertex_attribute_name));
 	}
 
+	/* Store resolution, so it can be changed in the UI. */
+	shader_point_density->cached_resolution = shader_point_density->resolution;
+
 	/* Single-threaded sampling of the voxel domain. */
 	RE_point_density_cache(scene,
 	                       pd,
@@ -3121,15 +3124,15 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self,
 {
 	NodeShaderTexPointDensity *shader_point_density = self->storage;
 	PointDensity *pd = &shader_point_density->pd;
+	const int resolution = shader_point_density->cached_resolution;
 
 	if (scene == NULL) {
 		*length = 0;
 		return;
 	}
 
-	*length = 4 * shader_point_density->resolution *
-	              shader_point_density->resolution *
-	              shader_point_density->resolution;
+	/* TODO(sergey): Will likely overflow, but how to pass size_t via RNA? */
+	*length = 4 * resolution * resolution * resolution;
 
 	if (*values == NULL) {
 		*values = MEM_mallocN(sizeof(float) * (*length), "point density dynamic array");
@@ -3137,13 +3140,14 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self,
 
 	/* Single-threaded sampling of the voxel domain. */
 	RE_point_density_sample(scene, pd,
-	                        shader_point_density->resolution,
+	                        resolution,
 	                        settings == 1,
 	                        *values);
 
 	/* We're done, time to clean up. */
 	BKE_texture_pointdensity_free_data(pd);
 	memset(pd, 0, sizeof(*pd));
+	shader_point_density->cached_resolution = 0.0f;
 }
 
 void rna_ShaderNodePointDensity_density_minmax(bNode *self,




More information about the Bf-blender-cvs mailing list