From 684971c2f27d59e7a0938d59e047dc4b71ce0c25 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 15 Mar 2021 14:43:02 +1100 Subject: WM: fallback to regular writing if auto-save can't access undo data While this is very unlikely, always write the autosave file, even if the `memfile` undo data is unexpectedly NULL. Also use CLG for logging warnings. --- source/blender/windowmanager/intern/wm_files.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index ca59174f8e8..a9b30f91bee 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -139,6 +139,8 @@ #include "wm_files.h" #include "wm_window.h" +#include "CLG_log.h" + static RecentFile *wm_file_history_find(const char *filepath); static void wm_history_file_free(RecentFile *recent); static void wm_history_files_free(void); @@ -147,6 +149,8 @@ static void wm_history_file_write(void); static void wm_test_autorun_revert_action_exec(bContext *C); +static CLG_LogRef LOG = {"wm.files"}; + /* -------------------------------------------------------------------- */ /** \name Misc Utility Functions * \{ */ @@ -1440,7 +1444,7 @@ static ImBuf *blend_file_thumb(const bContext *C, } else { /* '*thumb_pt' needs to stay NULL to prevent a bad thumbnail from being handled */ - fprintf(stderr, "blend_file_thumb failed to create thumbnail: %s\n", err_out); + CLOG_WARN(&LOG, "failed to create thumbnail: %s", err_out); thumb = NULL; } @@ -1649,14 +1653,18 @@ static void wm_autosave_write(Main *bmain, wmWindowManager *wm) wm_autosave_location(filepath); - if (U.uiflag & USER_GLOBALUNDO) { - /* fast save of last undobuffer, now with UI */ - struct MemFile *memfile = ED_undosys_stack_memfile_get_active(wm->undo_stack); - if (memfile) { - BLO_memfile_write_file(memfile, filepath); - } + /* Fast save of last undo-buffer, now with UI. */ + const bool use_memfile = (U.uiflag & USER_GLOBALUNDO) != 0; + MemFile *memfile = use_memfile ? ED_undosys_stack_memfile_get_active(wm->undo_stack) : NULL; + if (memfile != NULL) { + BLO_memfile_write_file(memfile, filepath); } else { + if (use_memfile) { + /* This is very unlikely, alert developers of this unexpected case. */ + CLOG_WARN(&LOG, "undo-data not found for writing, fallback to regular file write!"); + } + /* Save as regular blend file with recovery information. */ const int fileflags = (G.fileflags & ~G_FILE_COMPRESS) | G_FILE_RECOVER_WRITE; -- cgit v1.2.3