[Bf-blender-cvs] [64d39b7] gooseberry: Separate context freeing from task freeing in threaded particle updates to prevent double-freeing/invalid mem access.

Lukas Tönne noreply at git.blender.org
Thu Jan 8 12:42:05 CET 2015


Commit: 64d39b7378c55da184fd474aa38bf43bdc30156a
Author: Lukas Tönne
Date:   Thu Jan 8 12:40:27 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB64d39b7378c55da184fd474aa38bf43bdc30156a

Separate context freeing from task freeing in threaded particle updates
to prevent double-freeing/invalid mem access.

This can happen with the "virtual parents" feature, which generates both
parent and child paths. Each task free function also freed the shared
context, leading to double freeing.

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

M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_distribute.c
M	source/blender/blenkernel/intern/particle_system.c

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

diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 07ccc3f..b014531 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -356,6 +356,7 @@ void psys_get_dupli_path_transform(struct ParticleSimulationData *sim, struct Pa
                                    struct ParticleCacheKey *cache, float mat[4][4], float *scale);
 
 void psys_thread_context_init(struct ParticleThreadContext *ctx, struct ParticleSimulationData *sim);
+void psys_thread_context_free(struct ParticleThreadContext *ctx);
 void psys_tasks_create(struct ParticleThreadContext *ctx, int totpart, struct ParticleTask **r_tasks, int *r_numtasks);
 void psys_tasks_free(struct ParticleTask *tasks, int numtasks);
 
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 07beb03..82d5856 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -2619,6 +2619,8 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd
 	
 	psys_tasks_free(tasks_parent, numtasks_parent);
 	psys_tasks_free(tasks_child, numtasks_child);
+	
+	psys_thread_context_free(&ctx);
 }
 
 /* figure out incremental rotations along path starting from unit quat */
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index 90338e9..7a422ab 100644
--- a/source/blender/blenkernel/intern/particle_distribute.c
+++ b/source/blender/blenkernel/intern/particle_distribute.c
@@ -1140,6 +1140,8 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
 		ctx.dm->release(ctx.dm);
 	
 	psys_tasks_free(tasks, numtasks);
+	
+	psys_thread_context_free(&ctx);
 }
 
 /* ready for future use, to emit particles without geometry */
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index fa8a589..bdd87cb 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -472,13 +472,24 @@ void psys_tasks_create(ParticleThreadContext *ctx, int totpart, ParticleTask **r
 
 void psys_tasks_free(ParticleTask *tasks, int numtasks)
 {
-	ParticleThreadContext *ctx;
 	int i;
 	
 	if (numtasks == 0)
 		return;
 	
-	ctx = tasks[0].ctx;
+	/* threads */
+	for (i = 0; i < numtasks; ++i) {
+		if (tasks[i].rng)
+			BLI_rng_free(tasks[i].rng);
+		if (tasks[i].rng_path)
+			BLI_rng_free(tasks[i].rng_path);
+	}
+
+	MEM_freeN(tasks);
+}
+
+void psys_thread_context_free(ParticleThreadContext *ctx)
+{
 	/* path caching */
 	if (ctx->vg_length)
 		MEM_freeN(ctx->vg_length);
@@ -507,16 +518,6 @@ void psys_tasks_free(ParticleTask *tasks, int numtasks)
 	if (ctx->seams) MEM_freeN(ctx->seams);
 	//if (ctx->vertpart) MEM_freeN(ctx->vertpart);
 	BLI_kdtree_free(ctx->tree);
-
-	/* threads */
-	for (i = 0; i < numtasks; ++i) {
-		if (tasks[i].rng)
-			BLI_rng_free(tasks[i].rng);
-		if (tasks[i].rng_path)
-			BLI_rng_free(tasks[i].rng_path);
-	}
-
-	MEM_freeN(tasks);
 }
 
 static void initialize_particle_texture(ParticleSimulationData *sim, ParticleData *pa, int p)




More information about the Bf-blender-cvs mailing list