Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2016-02-23 13:58:27 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2016-02-23 14:01:16 +0300
commit48ed9fcb78275cb82f844ed91f9fe4d15d2570bd (patch)
tree2eadfc536057849ff3f2af4beb2bb1ae744ca3bc /source/blender/nodes
parent9c68ffc3b4d26a2cc571ee1a55482dbc447c7e80 (diff)
Fix memory leak in point density
The issue was happening when having unconnected point density which will cache data but will not free it because there's no actual call to the actual sampling. Now the idea is to make sure cache is zeroed on file load and undo and then caching via RNA will free the data if any exists. This could leave us with a single copy of cache in the node if it's not used, but it's quite small amount of memory and it's not leaking.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c
index 6205b0fa11f..006bd0cc8bb 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c
@@ -27,6 +27,10 @@
#include "../node_shader_util.h"
+#include "BKE_texture.h"
+
+#include "RE_render_ext.h"
+
/* **************** OUTPUT ******************** */
static bNodeSocketTemplate sh_node_tex_pointdensity_in[] = {
@@ -52,6 +56,26 @@ static void node_shader_init_tex_pointdensity(bNodeTree *UNUSED(ntree),
node->storage = point_density;
}
+static void node_shader_free_tex_pointdensity(bNode *node)
+{
+ NodeShaderTexPointDensity *point_density = node->storage;
+ PointDensity *pd = &point_density->pd;
+ RE_point_density_free(pd);
+ BKE_texture_pointdensity_free_data(pd);
+ memset(pd, 0, sizeof(*pd));
+ MEM_freeN(point_density);
+}
+
+static void node_shader_copy_tex_pointdensity(bNodeTree * UNUSED(dest_ntree),
+ bNode *dest_node,
+ bNode *src_node)
+{
+ dest_node->storage = MEM_dupallocN(src_node->storage);
+ NodeShaderTexPointDensity *point_density = dest_node->storage;
+ PointDensity *pd = &point_density->pd;
+ memset(pd, 0, sizeof(*pd));
+}
+
/* node type definition */
void register_node_type_sh_tex_pointdensity(void)
{
@@ -69,8 +93,8 @@ void register_node_type_sh_tex_pointdensity(void)
node_type_init(&ntype, node_shader_init_tex_pointdensity);
node_type_storage(&ntype,
"NodeShaderTexPointDensity",
- node_free_standard_storage,
- node_copy_standard_storage);
+ node_shader_free_tex_pointdensity,
+ node_shader_copy_tex_pointdensity);
nodeRegisterType(&ntype);
}