[Bf-blender-cvs] [8896c285098] soc-2020-info-editor: Feature: catch reports even if window manager is not fully initialized

Mateusz Grzeliński noreply at git.blender.org
Sun Jul 5 16:06:31 CEST 2020


Commit: 8896c285098930f30ec23c479db7b48ba58ce28c
Author: Mateusz Grzeliński
Date:   Sun Jul 5 15:54:05 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rB8896c285098930f30ec23c479db7b48ba58ce28c

Feature: catch reports even if window manager is not fully initialized

this allows us to show errors in info editor

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

M	source/blender/blenkernel/BKE_report.h
M	source/blender/blenkernel/intern/report.c
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_init_exit.c

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

diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h
index 063c0831a0d..6f0570ab999 100644
--- a/source/blender/blenkernel/BKE_report.h
+++ b/source/blender/blenkernel/BKE_report.h
@@ -59,6 +59,7 @@ void BKE_reports_print(ReportList *reports, ReportType level);
 
 Report *BKE_reports_last_displayable(ReportList *reports);
 
+void BKE_reports_move(ReportList *src, ReportList *dst);
 bool BKE_reports_contain(ReportList *reports, ReportType level);
 
 const char *BKE_report_type_str(ReportType type);
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index 43ab1a71647..b074995d4ab 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -305,6 +305,15 @@ Report *BKE_reports_last_displayable(ReportList *reports)
   return NULL;
 }
 
+void BKE_reports_move(ReportList *src, ReportList *dst)
+{
+  Report *report;
+  for (report = src->list.first; report; report = report->next) {
+    BLI_addtail(&dst->list, report);
+  }
+  BLI_listbase_clear(&src->list);
+}
+
 bool BKE_reports_contain(ReportList *reports, ReportType level)
 {
   Report *report;
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index d5a240a358e..f13b41799e5 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -844,7 +844,7 @@ const char *WM_init_state_app_template_get(void)
  * Template to use instead of the template defined in user-preferences.
  * When not-null, this is written into the user preferences.
  */
-void wm_homefile_read(bContext *C,
+void wm_homefile_read(struct bContext *C,
                       ReportList *reports,
                       bool use_factory_settings,
                       bool use_empty_data,
@@ -966,7 +966,7 @@ void wm_homefile_read(bContext *C,
   /* load preferences before startup.blend */
   if (use_userdef) {
     if (!use_factory_settings && BLI_exists(filepath_userdef)) {
-      UserDef *userdef = BKE_blendfile_userdef_read(filepath_userdef, NULL);
+      UserDef *userdef = BKE_blendfile_userdef_read(filepath_userdef, reports);
       if (userdef != NULL) {
         BKE_blender_userdef_data_set_and_free(userdef);
         userdef = NULL;
@@ -1025,7 +1025,7 @@ void wm_homefile_read(bContext *C,
                                        .is_startup = true,
                                        .skip_flags = skip_flags | BLO_READ_SKIP_USERDEF,
                                    },
-                                   NULL);
+                                   reports);
     }
     if (BLI_listbase_is_empty(&U.themes)) {
       if (G.debug & G_DEBUG) {
@@ -1066,7 +1066,7 @@ void wm_homefile_read(bContext *C,
                                                  .is_startup = true,
                                                  .skip_flags = skip_flags,
                                              },
-                                             NULL);
+                                             reports);
 
     if (use_data && BLI_listbase_is_empty(&wmbase)) {
       wm_clear_default_size(C);
@@ -1100,7 +1100,7 @@ void wm_homefile_read(bContext *C,
       UserDef *userdef_template = NULL;
       /* just avoids missing file warning */
       if (BLI_exists(temp_path)) {
-        userdef_template = BKE_blendfile_userdef_read(temp_path, NULL);
+        userdef_template = BKE_blendfile_userdef_read(temp_path, reports);
       }
       if (userdef_template == NULL) {
         /* we need to have preferences load to overwrite preferences from previous template */
@@ -1407,6 +1407,7 @@ bool write_crash_blend(void)
 
   BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path));
   BLI_path_extension_replace(path, sizeof(path), "_crash.blend");
+  // todo add reports and print them in log
   if (BLO_write_file(G_MAIN, path, G.fileflags, &(const struct BlendFileWriteParams){0}, NULL)) {
     printf("written: %s\n", path);
     return 1;
@@ -1641,6 +1642,7 @@ void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *UNUSED(wt))
     ED_editors_flush_edits(bmain);
 
     /* Error reporting into console. */
+    // todo add reports and log them
     BLO_write_file(bmain, filepath, fileflags, &(const struct BlendFileWriteParams){0}, NULL);
   }
   /* do timer after file write, just in case file write takes a long time */
@@ -3087,6 +3089,7 @@ static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_dat
   wmWindow *win = CTX_wm_window(C);
   UI_popup_block_close(C, win, arg_block);
 
+  // todo add reports and log them
   int modified_images_count = ED_image_save_all_modified_info(CTX_data_main(C), NULL);
   if (modified_images_count > 0 && save_images_when_file_is_closed) {
     if (ED_image_should_save_modified(bmain)) {
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index cb5a039765a..2afd7e24c95 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -276,6 +276,14 @@ void WM_init(bContext *C, int argc, const char **argv)
   /* reports cant be initialized before the wm,
    * but keep before file reading, since that may report errors */
   wm_init_reports(C);
+  /* on startup wm is not initialized, thus reports also will initialize
+   * in that case, use local copy of reports */
+  ReportList *reports = CTX_wm_reports(C);
+  bool use_context_reports = reports != NULL;
+  if (!use_context_reports) {
+    reports = MEM_mallocN(sizeof(*reports), "WMReports");
+    BKE_reports_init(reports, RPT_STORE);
+  }
 
   WM_msgbus_types_init();
 
@@ -290,8 +298,9 @@ void WM_init(bContext *C, int argc, const char **argv)
 
   BLI_assert((G.fileflags & G_FILE_NO_UI) == 0);
 
+  /* after this it is, use CTX_wm_reports */
   wm_homefile_read(C,
-                   NULL,
+                   reports,
                    G.factory_startup,
                    false,
                    use_data,
@@ -299,6 +308,11 @@ void WM_init(bContext *C, int argc, const char **argv)
                    NULL,
                    WM_init_state_app_template_get(),
                    &is_factory_startup);
+  /* now reports from context are initialized and we do not need reports */
+  if (!use_context_reports) {
+    BKE_reports_move(reports, CTX_wm_reports(C));
+    MEM_freeN(reports);
+  }
 
   /* Call again to set from userpreferences... */
   BLT_lang_set(NULL);
@@ -335,6 +349,7 @@ void WM_init(bContext *C, int argc, const char **argv)
    * Will try fix when the crash can be repeated. - campbell. */
 
 #ifdef WITH_PYTHON
+  // todo throws
   BPY_context_set(C); /* necessary evil */
   BPY_python_start(argc, argv);



More information about the Bf-blender-cvs mailing list