[Bf-blender-cvs] [2c0ca85a0c5] soc-2020-info-editor: Fixes for memory management

Mateusz Grzeliński noreply at git.blender.org
Tue Jun 30 17:24:57 CEST 2020


Commit: 2c0ca85a0c58bb4a8648152a36b092e11ed293ba
Author: Mateusz Grzeliński
Date:   Tue Jun 30 10:55:44 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rB2c0ca85a0c58bb4a8648152a36b092e11ed293ba

Fixes for memory management

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

M	source/blender/editors/space_info/info_report.c
M	source/blender/editors/space_info/space_info.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/WM_types.h

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

diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c
index d956d5ba1b5..00c2b504aed 100644
--- a/source/blender/editors/space_info/info_report.c
+++ b/source/blender/editors/space_info/info_report.c
@@ -417,9 +417,13 @@ ReportList *clog_to_report_list()
 {
   ReportList *reports = MEM_mallocN(sizeof(*reports), "ClogConvertedToReportList");
   BKE_reports_init(reports, RPT_STORE);
+  ListBase *records = CLG_log_record_get();
 
-  // todo there might be no logs in log records
-  CLG_LogRecord *log = CLG_log_record_get()->first, *log_iter = NULL;
+  if (BLI_listbase_is_empty(records)) {
+    return reports;
+  }
+
+  CLG_LogRecord *log = records->first;
 
   while (log) {
     DynStr *dynStr = BLI_dynstr_new();
@@ -451,8 +455,9 @@ ReportList *clog_to_report_list()
     }
     MEM_freeN(cstr);
     BLI_dynstr_free(dynStr);
-    log_iter = log->next;
-    log = log_iter;
+//    log_iter = log->next;
+//    log = log_iter;
+    log = log->next;
   }
   return reports;
 }
diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c
index 54307f2beea..87dc3e2026c 100644
--- a/source/blender/editors/space_info/space_info.c
+++ b/source/blender/editors/space_info/space_info.c
@@ -22,6 +22,7 @@
  */
 
 #include <BKE_global.h>
+#include <BKE_main.h>
 #include <BKE_report.h>
 #include <stdio.h>
 #include <string.h>
@@ -101,13 +102,15 @@ static void info_free(SpaceLink *sl)
   }
 }
 
-/* spacetype; init callback */
-static void info_init(struct wmWindowManager *wm, ScrArea *area)
+static void info_report_source_update(wmWindowManager *wm, SpaceInfo *sinfo)
 {
-  SpaceInfo *sinfo = area->spacedata.first;
   switch (sinfo->view) {
     case INFO_VIEW_REPORTS: {
-      BLI_assert(sinfo->active_reports == NULL || sinfo->active_reports == &wm->reports);
+      if (sinfo->active_reports != &wm->reports) {
+        /* reports come from log, deinit them*/
+        BKE_reports_clear(sinfo->active_reports);
+        MEM_freeN(sinfo->active_reports);
+      }
       sinfo->active_reports = &wm->reports;
       break;
     }
@@ -120,13 +123,28 @@ static void info_init(struct wmWindowManager *wm, ScrArea *area)
   }
 }
 
+/* spacetype; init callback */
+static void info_init(struct wmWindowManager *wm, ScrArea *area)
+{
+  SpaceInfo *sinfo = area->spacedata.first;
+  if (sinfo->active_reports == NULL) {
+    switch (sinfo->view) {
+      case INFO_VIEW_REPORTS: {
+        sinfo->active_reports = &wm->reports;
+        break;
+      }
+      case INFO_VIEW_CLOG: {
+        sinfo->active_reports = clog_to_report_list();
+        break;
+      }
+    }
+  }
+}
+
 static SpaceLink *info_duplicate(SpaceLink *sl)
 {
-  SpaceInfo *sinfo_old = (SpaceInfo *)sl;
   SpaceInfo *sinfo_new = MEM_dupallocN(sl);
-  if (sinfo_new->view == INFO_VIEW_CLOG) {
-    sinfo_old->active_reports = BKE_reports_duplicate(sinfo_new->active_reports);
-  }
+  sinfo_new->active_reports = NULL;  // will be reinitialized in info_init
 
   return (SpaceLink *)sinfo_new;
 }
@@ -226,42 +244,22 @@ static void info_header_region_draw(const bContext *C, ARegion *region)
   ED_region_header(C, region);
 }
 
-#include <BKE_main.h>
-
-static void info_report_source_update(wmWindowManager *wm, SpaceInfo *sinfo)
-{
-  switch (sinfo->view) {
-    case INFO_VIEW_REPORTS: {
-      if (sinfo->active_reports != &wm->reports) {
-        /* reports come from log, deinit them*/
-        BKE_reports_clear(sinfo->active_reports);
-        MEM_freeN(sinfo->active_reports);
-      }
-      sinfo->active_reports = &wm->reports;
-      break;
-    }
-    case INFO_VIEW_CLOG: {
-      if (sinfo->active_reports == &wm->reports) {
-        sinfo->active_reports = clog_to_report_list();
-      }
-      break;
-    }
-  }
-}
-
 static void info_main_region_listener(wmWindow *UNUSED(win),
                                       ScrArea *area,
                                       ARegion *region,
                                       wmNotifier *wmn,
                                       const Scene *UNUSED(scene))
 {
-   SpaceInfo *sinfo = area->spacedata.first;
+  SpaceInfo *sinfo = area->spacedata.first;
 
   /* context changes */
   switch (wmn->category) {
     case NC_SPACE:
       if (wmn->data == ND_SPACE_INFO_REPORT) {
         /* redraw also but only for report view, could do less redraws by checking the type */
+        ED_region_tag_redraw(region);
+      }
+      else if (wmn->data == ND_SPACE_INFO_CHANGE_REPORT_SOURCE) {
         // todo this is very bad
         Main *bmain = G_MAIN;
         wmWindowManager *wm = bmain->wm.first;
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 0d47cddc4ce..9bd92fca41c 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -6099,7 +6099,7 @@ static void rna_def_space_info(BlenderRNA *brna)
   RNA_def_property_enum_items(prop, view_type_items);
   RNA_def_property_ui_text(prop, "View reports or logs", "");
   RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
-  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_INFO_REPORT, NULL);
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_INFO_CHANGE_REPORT_SOURCE, NULL);
 }
 
 static void rna_def_space_userpref(BlenderRNA *brna)
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 4acce793707..2a50618226f 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -419,6 +419,7 @@ typedef struct wmNotifier {
 #define ND_SPACE_CHANGED (18 << 16) /*sent to a new editor type after it's replaced an old one*/
 #define ND_SPACE_CLIP (19 << 16)
 #define ND_SPACE_FILE_PREVIEW (20 << 16)
+#define ND_SPACE_INFO_CHANGE_REPORT_SOURCE (21 << 16)
 
 /* subtype, 256 entries too */
 #define NOTE_SUBTYPE 0x0000FF00



More information about the Bf-blender-cvs mailing list