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
This commit is contained in:
parent
302bba1665
commit
7a6b46aac5
Notes:
blender-bot
2023-02-14 03:30:41 +01:00
Referenced by commit 2b9eea17cc
, Particles: change default name to "ParticleSystem"
Referenced by issue #86366, Vertex group for new particle system with same settings resets.
Referenced by issue #62163, duplicate particle settings crashes blender
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue