Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-02-26 08:30:08 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-02-26 08:32:49 +0300
commit9059ee81ef6be5c1eb6157db426165f5a9c2b74a (patch)
treeb89b0ee4801dd962fb3c13baf8135e293d611b2f
parentb7939a059f9056ae57b4720a4c98dbe9025de407 (diff)
Fix particle-edit crash on undo/redo
Undo/redo was crashing & asserting. There ware two bugs: - Entering particle system edit-mode requires an evaluated depsgraph. - The active object could get out of sync when undo/redo moves between different modes. The new test 'view3d_mesh_particle_edit_mode_simple' in `tests/ui_simulate/test_undo.py` exposes both issues.
-rw-r--r--source/blender/editors/physics/CMakeLists.txt1
-rw-r--r--source/blender/editors/physics/particle_edit.c3
-rw-r--r--source/blender/editors/physics/particle_edit_undo.c16
3 files changed, 17 insertions, 3 deletions
diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt
index 2b9d9aaa0e1..a607663763e 100644
--- a/source/blender/editors/physics/CMakeLists.txt
+++ b/source/blender/editors/physics/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
../../makesdna
../../makesrna
../../windowmanager
+ ../../../../intern/clog
../../../../intern/glew-mx
../../../../intern/guardedalloc
../../../../intern/mantaflow/extern
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index ec3eb9c6a3a..d0ebac82c90 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -5395,6 +5395,9 @@ static void free_all_psys_edit(Object *object)
void ED_object_particle_edit_mode_enter_ex(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
+ /* Needed so #ParticleSystemModifierData.mesh_final is set. */
+ BKE_scene_graph_evaluated_ensure(depsgraph, G_MAIN);
+
PTCacheEdit *edit;
ob->mode |= OB_MODE_PARTICLE_EDIT;
diff --git a/source/blender/editors/physics/particle_edit_undo.c b/source/blender/editors/physics/particle_edit_undo.c
index 5d2e0e5b6ef..c764a5fd80f 100644
--- a/source/blender/editors/physics/particle_edit_undo.c
+++ b/source/blender/editors/physics/particle_edit_undo.c
@@ -27,6 +27,8 @@
#include "MEM_guardedalloc.h"
+#include "CLG_log.h"
+
#include "DNA_meshdata_types.h"
#include "DNA_scene_types.h"
#include "DNA_windowmanager_types.h"
@@ -44,11 +46,15 @@
#include "ED_object.h"
#include "ED_particle.h"
#include "ED_physics.h"
+#include "ED_undo.h"
#include "particle_edit_utildefines.h"
#include "physics_intern.h"
+/** Only needed this locally. */
+static CLG_LogRef LOG = {"ed.undo.particle_edit"};
+
/* -------------------------------------------------------------------- */
/** \name Undo Conversion
* \{ */
@@ -251,13 +257,13 @@ static void particle_undosys_step_decode(struct bContext *C,
bool UNUSED(is_final))
{
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
- /* TODO(campbell): undo_system: use low-level API to set mode. */
- ED_object_mode_set_ex(C, OB_MODE_PARTICLE_EDIT, false, NULL);
- BLI_assert(particle_undosys_poll(C));
ParticleUndoStep *us = (ParticleUndoStep *)us_p;
Scene *scene = us->scene_ref.ptr;
Object *ob = us->object_ref.ptr;
+
+ ED_object_particle_edit_mode_enter_ex(depsgraph, scene, ob);
+
PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob);
if (edit) {
undoptcache_to_editcache(&us->data, edit);
@@ -267,6 +273,10 @@ static void particle_undosys_step_decode(struct bContext *C,
BKE_particle_batch_cache_dirty_tag(edit->psys, BKE_PARTICLE_BATCH_DIRTY_ALL);
}
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
+
+ ED_undo_object_set_active_or_warn(scene, CTX_data_view_layer(C), ob, us_p->name, &LOG);
+
+ BLI_assert(particle_undosys_poll(C));
}
else {
BLI_assert(0);