[Bf-blender-cvs] [684971c2f27] master: WM: fallback to regular writing if auto-save can't access undo data

Campbell Barton noreply at git.blender.org
Mon Mar 15 04:54:13 CET 2021


Commit: 684971c2f27d59e7a0938d59e047dc4b71ce0c25
Author: Campbell Barton
Date:   Mon Mar 15 14:43:02 2021 +1100
Branches: master
https://developer.blender.org/rB684971c2f27d59e7a0938d59e047dc4b71ce0c25

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.

===================================================================

M	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;



More information about the Bf-blender-cvs mailing list