diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-03-05 17:24:54 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-03-05 17:24:54 +0300 |
commit | 7a6b46aac56b2a529370129bbedcd20f408c6352 (patch) | |
tree | 284f6c4d6b990d5acfebf3bb72c1df4bfcbd7ade /source/blender/blenkernel | |
parent | 302bba1665154edc81addfa18d7b8bc8bff6a18d (diff) |
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
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_particle.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 18 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 7 |
3 files changed, 16 insertions, 11 deletions
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; |