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:
2019-03-05 15:24:54 +01:00
parent 302bba1665
commit 7a6b46aac5
4 changed files with 21 additions and 13 deletions

View File

@@ -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;