Particle edit: Fix generation of KD tree for emitters
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 15 May 2018 14:15:13 +0000 (16:15 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 15 May 2018 15:20:02 +0000 (17:20 +0200)
Fixes crahs using puff brush with copy-on-write.

source/blender/editors/physics/particle_edit.c
source/blender/editors/physics/particle_object.c
source/blender/editors/physics/physics_intern.h

index 7f8f08beaacd67f222ee81972907ad5b5c72115a..3df934a8dca2a5d849db0e163944991f164457fe 100644 (file)
@@ -1101,10 +1101,12 @@ void recalc_lengths(PTCacheEdit *edit)
 }
 
 /* calculate a tree for finding nearest emitter's vertice */
-void recalc_emitter_field(Object *ob, ParticleSystem *psys)
+void recalc_emitter_field(Depsgraph *depsgraph, Object *ob, ParticleSystem *psys)
 {
-       DerivedMesh *dm=psys_get_modifier(ob, psys)->dm_final;
-       PTCacheEdit *edit= psys->edit;
+       Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
+       ParticleSystem *psys_eval = psys_eval_get(depsgraph, ob, psys);
+       DerivedMesh *dm = psys_get_modifier(object_eval, psys_eval)->dm_final;
+       PTCacheEdit *edit = psys->edit;
        float *vec, *nor;
        int i, totface /*, totvert*/;
 
@@ -4451,7 +4453,7 @@ void PE_create_particle_edit(
 
                recalc_lengths(edit);
                if (psys && !cache)
-                       recalc_emitter_field(ob, psys);
+                       recalc_emitter_field(depsgraph, ob, psys);
 
                PE_update_object(depsgraph, scene, ob, 1);
        }
@@ -4497,7 +4499,7 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
                /* mesh may have changed since last entering editmode.
                 * note, this may have run before if the edit data was just created, so could avoid this and speed up a little */
                if (edit && edit->psys)
-                       recalc_emitter_field(ob, edit->psys);
+                       recalc_emitter_field(depsgraph, ob, edit->psys);
                
                toggle_particle_cursor(C, 1);
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, NULL);
index 76308fe1fd7ae8bedc02e4920506319b3c80400f..79d52abb32d18a75a59697dc81c67b6dd48e3773 100644 (file)
@@ -952,7 +952,7 @@ static void copy_particle_edit(
        UI_GetThemeColor3ubv(TH_WIRE, edit->nosel_col);
        
        recalc_lengths(edit);
-       recalc_emitter_field(ob, psys);
+       recalc_emitter_field(depsgraph, ob, psys);
        PE_update_object(depsgraph, scene, ob, true);
 }
 
index 108c033a87c5eaed04275a7ee2f9f1dcf27ba901..e94f582141b2b7ab1b9ef86b745181f6b99830ac 100644 (file)
@@ -74,7 +74,7 @@ void PE_create_particle_edit(
         struct Depsgraph *depsgraph, struct Scene *scene,
         struct Object *ob, struct PointCache *cache, struct ParticleSystem *psys);
 void recalc_lengths(struct PTCacheEdit *edit);
-void recalc_emitter_field(struct Object *ob, struct ParticleSystem *psys);
+void recalc_emitter_field(struct Depsgraph *depsgraph, struct Object *ob, struct ParticleSystem *psys);
 void update_world_cos(struct Depsgraph *depsgraph, struct Object *ob, struct PTCacheEdit *edit);
 
 /* particle_object.c */