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.
This commit is contained in:
Sergey Sharybin 2016-11-29 11:39:14 +01:00
parent 7ea2dedd59
commit 1ec5edcc96
Notes: blender-bot 2023-02-14 07:23:31 +01:00
Referenced by issue #50094, crash when viewport rendering point density texture
2 changed files with 11 additions and 4 deletions

View File

@ -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 */

View File

@ -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,