From 651b8fb14eb6ee5cbfa98bffe80a966a0753b14e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 19 Mar 2018 14:17:59 +0100 Subject: Undo: unified undo system w/ linear history - Use a single undo history for all operations. - UndoType's are registered and poll the context to check if they should be used when performing an undo push. - Mode switching is used to ensure the state is correct before undo data is restored. - Some undo types accumulate changes (image & text editing) others store the state multiple times (with de-duplication). This is supported by checking UndoStack.mode `ACCUMULATE` / `STORE`. - Each undo step stores ID datablocks they use with utilities to help manage restoring correct ID's. Needed since global undo is now mixed with other modes undo. - Currently performs each undo step when going up/down history Previously this wasn't done, making history fail in some cases. This can be optimized to skip some combinations of undo steps. grease-pencil is an exception which has not been updated since it integrates undo into the draw-session. See D3113 --- source/creator/creator_signals.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'source/creator/creator_signals.c') diff --git a/source/creator/creator_signals.c b/source/creator/creator_signals.c index 81e6178c502..feb108da289 100644 --- a/source/creator/creator_signals.c +++ b/source/creator/creator_signals.c @@ -64,6 +64,7 @@ #include "BKE_main.h" #include "BKE_report.h" + /* for passing information between creator and gameengine */ #ifdef WITH_GAMEENGINE # include "BL_System.h" @@ -75,6 +76,12 @@ #include "creator_intern.h" /* own include */ +// #define USE_WRITE_CRASH_BLEND +#ifdef USE_WRITE_CRASH_BLEND +# include "BKE_undo_system.h" +# include "BLO_undofile.h" +#endif + /* set breakpoints here when running in debug mode, useful to catch floating point errors */ #if defined(__linux__) || defined(_WIN32) || defined(OSX_SSE_FPE) static void sig_handle_fpe(int UNUSED(sig)) @@ -110,29 +117,32 @@ static void sig_handle_crash_backtrace(FILE *fp) static void sig_handle_crash(int signum) { + wmWindowManager *wm = G.main->wm.first; -#if 0 - { - char fname[FILE_MAX]; +#ifdef USE_WRITE_CRASH_BLEND + if (wm->undo_stack) { + struct MemFile *memfile = BKE_undosys_stack_memfile_get_active(wm->undo_stack); + if (memfile) { + char fname[FILE_MAX]; - if (!G.main->name[0]) { - BLI_make_file_string("/", fname, BKE_tempdir_base(), "crash.blend"); - } - else { - BLI_strncpy(fname, G.main->name, sizeof(fname)); - BLI_replace_extension(fname, sizeof(fname), ".crash.blend"); - } + if (!G.main->name[0]) { + BLI_make_file_string("/", fname, BKE_tempdir_base(), "crash.blend"); + } + else { + BLI_strncpy(fname, G.main->name, sizeof(fname)); + BLI_replace_extension(fname, sizeof(fname), ".crash.blend"); + } - printf("Writing: %s\n", fname); - fflush(stdout); + printf("Writing: %s\n", fname); + fflush(stdout); - BKE_undo_save_file(fname); + BLO_memfile_write_file(memfile, fname); + } } #endif FILE *fp; char header[512]; - wmWindowManager *wm = G.main->wm.first; char fname[FILE_MAX]; @@ -338,4 +348,4 @@ void main_signal_setup_fpe(void) #endif } -#endif /* WITH_PYTHON_MODULE */ \ No newline at end of file +#endif /* WITH_PYTHON_MODULE */ -- cgit v1.2.3