Cleanup depsgraph access in particle_edit.c
authorPhilipp Oeser <info@graphics-engineer.com>
Tue, 15 Oct 2019 10:22:43 +0000 (12:22 +0200)
committerPhilipp Oeser <info@graphics-engineer.com>
Thu, 17 Oct 2019 11:17:05 +0000 (13:17 +0200)
'PE_set_data' / 'PE_set_view3d_data' would give us a depsgraph already,
so use it.

Also fix access to PEData->depsgraph without calling 'PE_set_data' prior.

Addresses concern raised in rBcf2c09002fae.

Reviewed By: sergey

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

source/blender/editors/physics/particle_edit.c

index 3978f7ba3b5b12b39a1f04e8cc18391253a8dca4..f16a372cb3c321fb580682be6d3e93ff3e084b32 100644 (file)
@@ -470,8 +470,7 @@ static void PE_set_view3d_data(bContext *C, PEData *data)
 {
   PE_set_data(C, data);
 
-  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
-  ED_view3d_viewcontext_init(C, &data->vc, depsgraph);
+  ED_view3d_viewcontext_init(C, &data->vc, data->depsgraph);
 
   if (!XRAY_ENABLED(data->vc.v3d)) {
     if (data->vc.v3d->flag & V3D_INVALID_BACKBUF) {
@@ -1811,10 +1810,13 @@ bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool desele
   PEData data;
   Scene *scene = CTX_data_scene(C);
   Object *ob = CTX_data_active_object(C);
-  PTCacheEdit *edit = PE_get_current(data.depsgraph, scene, ob);
   POINT_P;
   KEY_K;
 
+  PE_set_view3d_data(C, &data);
+
+  PTCacheEdit *edit = PE_get_current(data.depsgraph, scene, ob);
+
   if (!PE_start_edit(edit)) {
     return false;
   }
@@ -1828,7 +1830,6 @@ bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool desele
     }
   }
 
-  PE_set_view3d_data(C, &data);
   data.mval = mval;
   data.rad = ED_view3d_select_dist_px();
 
@@ -1997,7 +1998,6 @@ static const EnumPropertyItem select_random_type_items[] = {
 
 static int select_random_exec(bContext *C, wmOperator *op)
 {
-  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
   PEData data;
   int type;
 
@@ -2017,7 +2017,7 @@ static int select_random_exec(bContext *C, wmOperator *op)
 
   PE_set_data(C, &data);
   data.select_action = SEL_SELECT;
-  edit = PE_get_current(depsgraph, data.scene, data.ob);
+  edit = PE_get_current(data.depsgraph, data.scene, data.ob);
 
   rng = BLI_rng_new_srandom(seed);
 
@@ -4940,7 +4940,7 @@ static void shape_cut(PEData *data, int pa_index)
 
 static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op))
 {
-  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   Scene *scene = CTX_data_scene(C);
   Object *ob = CTX_data_active_object(C);
   ParticleEditSettings *pset = PE_settings(scene);