diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c2a18033b44..09e953b6ec6 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3673,7 +3673,7 @@ static void direct_link_object(BlendDataReader *reader, Object *ob) /* For undo we want to stay in object mode during undo presses, so keep some edit modes * disabled. * TODO: Check if we should not disable more edit modes here? */ - ob->mode &= ~(OB_MODE_EDIT | OB_MODE_PARTICLE_EDIT); + ob->mode &= ~(OB_MODE_EDIT | OB_MODE_PARTICLE_EDIT | OB_MODE_ALL_SCULPT); } BLO_read_data_address(reader, &ob->adt); @@ -5655,7 +5655,7 @@ static void read_libblock_undo_restore_identical( } /* For undo we stay in object mode during undo presses, so keep editmode disabled for re-used * data-blocks too. */ - ob->mode &= ~OB_MODE_EDIT; + ob->mode &= ~(OB_MODE_EDIT | OB_MODE_PARTICLE_EDIT | OB_MODE_ALL_SCULPT); } } diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c index 2df26abe8b3..03c9b8272c6 100644 --- a/source/blender/editors/undo/memfile_undo.c +++ b/source/blender/editors/undo/memfile_undo.c @@ -36,6 +36,7 @@ #include "BKE_lib_query.h" #include "BKE_main.h" #include "BKE_node.h" +#include "BKE_paint.h" #include "BKE_scene.h" #include "BKE_undo_system.h" @@ -219,6 +220,17 @@ static void memfile_undosys_step_decode(struct bContext *C, bmain, id, memfile_undosys_step_id_reused_cb, NULL, IDWALK_READONLY); } + /* Sculpt mode has its own undo system, so when we get back from it into object mode, + * clearing `ob->mode` flag is not enough, we also need to clean up the sculpt session data, + * otherwise the object does not go back properly in Object mode. */ + if (GS(id->name) == ID_OB) { + Object *ob = (Object *)id; + if (ob->sculpt != NULL) { + BKE_sculptsession_free(ob); + DEG_id_tag_update_ex(bmain, id, ID_RECALC_COPY_ON_WRITE); + } + } + /* Tag depsgraph to update data-block for changes that happened between the * current and the target state, see direct_link_id_restore_recalc(). */ if (id->recalc) {