[Bf-blender-cvs] [7a6b46aac56] master: Fix T62163: Duplicating particle system results in crash

Jacques Lucke noreply at git.blender.org
Tue Mar 5 15:25:14 CET 2019


Commit: 7a6b46aac56b2a529370129bbedcd20f408c6352
Author: Jacques Lucke
Date:   Tue Mar 5 15:24:54 2019 +0100
Branches: master
https://developer.blender.org/rB7a6b46aac56b2a529370129bbedcd20f408c6352

Fix T62163: Duplicating particle system results in crash

There were two problems:
1. `mesh_get_eval_final` has to be called with the evaluated object.
2. Particle systems have to have unique names within an object.
The depsgraph seems to use the particle system name as identifier.
This issue is actually independent of duplication.
The old code used a small hack to create unique names.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D4451

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

M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/editors/physics/particle_object.c

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

diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 129bd1aaa2c..715d8670071 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -353,6 +353,8 @@ void psys_reset(struct ParticleSystem *psys, int mode);
 
 void psys_find_parents(struct ParticleSimulationData *sim, const bool use_render_params);
 
+void psys_unique_name(struct Object *object, struct ParticleSystem *psys, const char *defname);
+
 void psys_cache_paths(struct ParticleSimulationData *sim, float cfra, const bool use_render_params);
 void psys_cache_edit_paths(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct PTCacheEdit *edit, float cfra, const bool use_render_params);
 void psys_cache_child_paths(struct ParticleSimulationData *sim, float cfra, const bool editupdate, const bool use_render_params);
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 5d29c8c5941..3146e3f9fd2 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3062,6 +3062,10 @@ ModifierData *object_add_particle_system(Main *bmain, Scene *scene, Object *ob,
 	if (!ob || ob->type != OB_MESH)
 		return NULL;
 
+	if (name == NULL) {
+		name = DATA_("ParticleSettings");
+	}
+
 	psys = ob->particlesystem.first;
 	for (; psys; psys = psys->next)
 		psys->flag &= ~PSYS_CURRENT;
@@ -3069,20 +3073,12 @@ ModifierData *object_add_particle_system(Main *bmain, Scene *scene, Object *ob,
 	psys = MEM_callocN(sizeof(ParticleSystem), "particle_system");
 	psys->pointcache = BKE_ptcache_add(&psys->ptcaches);
 	BLI_addtail(&ob->particlesystem, psys);
+	psys_unique_name(ob, psys, name);
 
-	psys->part = BKE_particlesettings_add(bmain, DATA_("ParticleSettings"));
-
-	if (BLI_listbase_count_at_most(&ob->particlesystem, 2) > 1)
-		BLI_snprintf(psys->name, sizeof(psys->name), DATA_("ParticleSystem %i"), BLI_listbase_count(&ob->particlesystem));
-	else
-		BLI_strncpy(psys->name, DATA_("ParticleSystem"), sizeof(psys->name));
+	psys->part = BKE_particlesettings_add(bmain, psys->name);
 
 	md = modifier_new(eModifierType_ParticleSystem);
-
-	if (name)
-		BLI_strncpy_utf8(md->name, name, sizeof(md->name));
-	else
-		BLI_snprintf(md->name, sizeof(md->name), DATA_("ParticleSystem %i"), BLI_listbase_count(&ob->particlesystem));
+	BLI_strncpy(md->name, psys->name, sizeof(md->name));
 	modifier_unique_name(&ob->modifiers, md);
 
 	psmd = (ParticleSystemModifierData *) md;
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 7c6ebe79b58..2975eaaf5fc 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -56,6 +56,7 @@
 #include "BLI_task.h"
 #include "BLI_threads.h"
 #include "BLI_linklist.h"
+#include "BLI_string_utils.h"
 
 #include "BKE_animsys.h"
 #include "BKE_boids.h"
@@ -186,6 +187,12 @@ void psys_reset(ParticleSystem *psys, int mode)
 	psys->tot_fluidsprings = psys->alloc_fluidsprings = 0;
 }
 
+void psys_unique_name(Object *object, ParticleSystem *psys, const char *defname)
+{
+	BLI_uniquename(&object->particlesystem, psys, defname, '.',
+	    offsetof(ParticleSystem, name), sizeof(psys->name));
+}
+
 static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
 {
 	ParticleSystem *psys = sim->psys;
diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c
index e10df28a75e..3b063fd7164 100644
--- a/source/blender/editors/physics/particle_object.c
+++ b/source/blender/editors/physics/particle_object.c
@@ -51,6 +51,7 @@
 #include "BKE_report.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
 #include "DEG_depsgraph_build.h"
 
 #include "RNA_access.h"
@@ -1069,7 +1070,8 @@ static bool copy_particle_systems_to_object(const bContext *C,
 	psys_start = totpsys > 0 ? tmp_psys[0] : NULL;
 
 	/* Get the evaluated mesh (psys and their modifiers have not been appended yet) */
-	final_mesh = mesh_get_eval_final(depsgraph, scene, ob_to, cdmask);
+	Object *ob_to_eval = DEG_get_evaluated_object(depsgraph, ob_to);
+	final_mesh = mesh_get_eval_final(depsgraph, scene, ob_to_eval, cdmask);
 
 	/* now append psys to the object and make modifiers */
 	for (i = 0, psys_from = PSYS_FROM_FIRST;
@@ -1082,6 +1084,7 @@ static bool copy_particle_systems_to_object(const bContext *C,
 
 		/* append to the object */
 		BLI_addtail(&ob_to->particlesystem, psys);
+		psys_unique_name(ob_to, psys, "");
 
 		/* add a particle system modifier for each system */
 		md = modifier_new(eModifierType_ParticleSystem);
@@ -1089,7 +1092,7 @@ static bool copy_particle_systems_to_object(const bContext *C,
 		/* push on top of the stack, no use trying to reproduce old stack order */
 		BLI_addtail(&ob_to->modifiers, md);
 
-		BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", i);
+		BLI_strncpy(md->name, psys->name, sizeof(md->name));
 		modifier_unique_name(&ob_to->modifiers, (ModifierData *)psmd);
 
 		psmd->psys = psys;



More information about the Bf-blender-cvs mailing list