From 1ec5edcc9669f46b1f0fd29c765a326ea525e7f3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 29 Nov 2016 11:39:14 +0100 Subject: 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. --- source/blender/makesdna/DNA_node_types.h | 3 +++ source/blender/makesrna/intern/rna_nodetree.c | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 46b30f41f5b..3a7e2b6f7f8 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 47e9d989dbf..34002f8d550 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, -- cgit v1.2.3