[Bf-blender-cvs] [aa48aca0a7e] soc-2019-bevel-profiles: Fixed saving and loading of profile widget and profile widget memory leaks.

Hans Goudey noreply at git.blender.org
Tue Jul 2 23:25:57 CEST 2019


Commit: aa48aca0a7e331f8305c430a6c73e3bac502e66b
Author: Hans Goudey
Date:   Tue Jul 2 17:24:42 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rBaa48aca0a7e331f8305c430a6c73e3bac502e66b

Fixed saving and loading of profile widget and profile widget memory leaks.

Also consolidated ProfilePath and ProfileWidget structs. In the process I renamed
the files that define it, and renamed some other variables for consistency.

This also includes some small changes to the profile widget UI.

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

M	source/blender/CMakeLists.txt
R076	source/blender/blenkernel/BKE_profile_path.h	source/blender/blenkernel/BKE_profile_widget.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/modifier.c
R064	source/blender/blenkernel/intern/profile_path.c	source/blender/blenkernel/intern/profile_widget.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/bmesh/operators/bmo_bevel.c
M	source/blender/bmesh/tools/bmesh_bevel.c
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_templates.c
R081	source/blender/makesdna/DNA_profilepath_types.h	source/blender/makesdna/DNA_profilewidget_types.h
M	source/blender/makesdna/intern/makesdna.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_profile.c
M	source/blender/modifiers/intern/MOD_bevel.c

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

diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index b8c5f72e41c..77fa7e3ab81 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -68,7 +68,7 @@ set(SRC_DNA_INC
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_outliner_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_packedFile_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_particle_types.h
-  ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_profilepath_types.h
+  ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_profilewidget_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_rigidbody_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_scene_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_screen_types.h
diff --git a/source/blender/blenkernel/BKE_profile_path.h b/source/blender/blenkernel/BKE_profile_widget.h
similarity index 76%
rename from source/blender/blenkernel/BKE_profile_path.h
rename to source/blender/blenkernel/BKE_profile_widget.h
index affa5140ee7..93fbdcf2b78 100644
--- a/source/blender/blenkernel/BKE_profile_path.h
+++ b/source/blender/blenkernel/BKE_profile_widget.h
@@ -25,7 +25,6 @@
  */
 
 struct ProfileWidget;
-struct ProfilePath;
 struct ProfilePoint;
 
 /* HANS-TODO: Organize */
@@ -49,29 +48,29 @@ void profilewidget_evaluate(const struct ProfileWidget *prwdgt,
                             float *y_out);
 
 /* Length portion is the fraction of the total path length where we want the location */
-void profilepath_evaluate(const struct ProfilePath *prpath,
+void profilewidget_evaluate_portion(const struct ProfileWidget *prwdgt,
                           float length_portion,
                           float *x_out,
                           float *y_out);
 
 /* Need to find the total length of the curve to sample a portion of it */
-float profilepath_total_length(const struct ProfilePath *prpath);
+float profilewidget_total_length(const struct ProfileWidget *prwdgt);
 
 /* Distance in 2D to the next point */
-float profilepath_linear_distance_to_next_point(const struct ProfilePath *prpath, int i);
+float profilewidget_linear_distance_to_next_point(const struct ProfileWidget *prwdgt, int i);
 
 
-void profilepath_reset(struct ProfilePath *prpath, int preset);
+void profilewidget_reset(struct ProfileWidget *prwdgt);
 
-void profilepath_remove(struct ProfilePath *prpath, const short flag);
+void profilewidget_remove(struct ProfileWidget *prwdgt, const short flag);
 
-bool profilepath_remove_point(struct ProfilePath *prpath, struct ProfilePoint *point);
+bool profilewidget_remove_point(struct ProfileWidget *prwdgt, struct ProfilePoint *point);
 
-struct ProfilePoint *profilepath_insert(struct ProfilePath *prpath, float x, float y);
+struct ProfilePoint *profilewidget_insert(struct ProfileWidget *prwdgt, float x, float y);
 
-void profilepath_reverse(struct ProfilePath *prpath);
+void profilewidget_reverse(struct ProfileWidget *prwdgt);
 
-void profilepath_handle_set(struct ProfilePath *prpath, int type);
+void profilewidget_handle_set(struct ProfileWidget *prwdgt, int type);
 
 /* Called for a complete update of the widget after modifications */
 void profilewidget_changed(struct ProfileWidget *prwdgt, const bool rem_doubles);
@@ -79,7 +78,7 @@ void profilewidget_changed(struct ProfileWidget *prwdgt, const bool rem_doubles)
 /* call before all evaluation functions */
 void profilewidget_initialize(struct ProfileWidget *prwdgt, int nsegments);
 
-void profilepath_fill_segment_table(const struct ProfilePath *prpath,
+void profilewidget_fill_segment_table(const struct ProfileWidget *prwdgt,
                                     double *x_table_out,
                                     double *y_table_out);
 
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index c15df299e1f..be3462d7060 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -177,7 +177,7 @@ set(SRC
   intern/pbvh.c
   intern/pbvh_bmesh.c
   intern/pointcache.c
-  intern/profile_path.c
+  intern/profile_widget.c
   intern/report.c
   intern/rigidbody.c
   intern/scene.c
@@ -317,7 +317,7 @@ set(SRC
   BKE_particle.h
   BKE_pbvh.h
   BKE_pointcache.h
-  BKE_profile_path.h
+  BKE_profile_widget.h
   BKE_report.h
   BKE_rigidbody.h
   BKE_scene.h
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 2254207e545..f2246bb3bd4 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -154,6 +154,7 @@ static void modifier_free_data_id_us_cb(void *UNUSED(userData),
 
 void modifier_free_ex(ModifierData *md, const int flag)
 {
+  printf("MODIFIER FREE EX\n");
   const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
   if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
@@ -338,6 +339,7 @@ static void modifier_copy_data_id_us_cb(void *UNUSED(userData),
 
 void modifier_copyData_ex(ModifierData *md, ModifierData *target, const int flag)
 {
+  printf("MODIFIER COPYDATA EX\n");
   const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
   target->mode = md->mode;
@@ -901,6 +903,7 @@ struct Mesh *modwrap_applyModifier(ModifierData *md,
                                    const ModifierEvalContext *ctx,
                                    struct Mesh *me)
 {
+  printf("MODWRAP APPLY MODIFIER\n");
   const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
   BLI_assert(CustomData_has_layer(&me->pdata, CD_NORMAL) == false);
 
diff --git a/source/blender/blenkernel/intern/profile_path.c b/source/blender/blenkernel/intern/profile_widget.c
similarity index 64%
rename from source/blender/blenkernel/intern/profile_path.c
rename to source/blender/blenkernel/intern/profile_widget.c
index 89616c37b5b..bd3cb093e55 100644
--- a/source/blender/blenkernel/intern/profile_path.c
+++ b/source/blender/blenkernel/intern/profile_widget.c
@@ -28,7 +28,7 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "DNA_profilepath_types.h"
+#include "DNA_profilewidget_types.h"
 #include "DNA_curve_types.h"
 
 #include "BLI_blenlib.h"
@@ -37,11 +37,11 @@
 #include "BLI_task.h"
 #include "BLI_threads.h"
 
-#include "BKE_profile_path.h"
+#include "BKE_profile_widget.h"
 #include "BKE_curve.h"
 #include "BKE_fcurve.h"
 
-#define DEBUG_PRWDGT 0
+#define DEBUG_PRWDGT 1
 #define DEBUG_PRWDGT_TABLE 1
 #define DEBUG_PRWDGT_EVALUATE 0
 #define DEBUG_PRWDGT_REVERSE 0
@@ -58,13 +58,13 @@ void profilewidget_set_defaults(ProfileWidget *prwdgt)
   BLI_rctf_init(&prwdgt->view_rect, 0.0f, 1.0f, 0.0f, 1.0f);
   prwdgt->clip_rect = prwdgt->view_rect;
 
-  prwdgt->profile->totpoint = 2;
-  prwdgt->profile->path = MEM_callocN(2 * sizeof(ProfilePoint), "path points");
+  prwdgt->totpoint = 2;
+  prwdgt->path = MEM_callocN(2 * sizeof(ProfilePoint), "path points");
 
-  prwdgt->profile->path[0].x = 1.0f;
-  prwdgt->profile->path[0].y = 0.0f;
-  prwdgt->profile->path[1].x = 1.0f;
-  prwdgt->profile->path[1].y = 1.0f;
+  prwdgt->path[0].x = 1.0f;
+  prwdgt->path[0].y = 0.0f;
+  prwdgt->path[1].x = 1.0f;
+  prwdgt->path[1].y = 1.0f;
 
   prwdgt->changed_timestamp = 0;
 }
@@ -76,10 +76,10 @@ struct ProfileWidget *profilewidget_add(int preset)
 #endif
 
   ProfileWidget *prwdgt = MEM_callocN(sizeof(ProfileWidget), "new profile widget");
-  prwdgt->profile = MEM_callocN(sizeof(ProfilePath), "new profile path");
 
   profilewidget_set_defaults(prwdgt);
-  profilepath_reset(prwdgt->profile, preset);
+  prwdgt->preset = preset;
+  profilewidget_reset(prwdgt);
   profilewidget_changed(prwdgt, false);
 
   return prwdgt;
@@ -91,20 +91,19 @@ void profilewidget_free_data(ProfileWidget *prwdgt)
   printf("PROFILEWIDGET FREE DATA\n");
 #endif
 
-  if (!prwdgt->profile) {
-    /* Why are you even here in the first place? */
-    printf("ProfileWidget has no profile\n"); /* HANS-TODO: Remove */
-    return;
+  if (prwdgt->path) {
+    MEM_freeN(prwdgt->path);
+    prwdgt->path = NULL;
   }
-  if (prwdgt->profile->path) {
-    MEM_freeN(prwdgt->profile->path);
-    prwdgt->profile->path = NULL;
+  else {
+#if DEBUG_PRWDGT
+  printf("The prwdgt had no path... probably a second redundant free call\n");
+#endif
   }
-  if (prwdgt->profile->table) {
-    MEM_freeN(prwdgt->profile->table);
-    prwdgt->profile->table = NULL;
+  if (prwdgt->table) {
+    MEM_freeN(prwdgt->table);
+    prwdgt->table = NULL;
   }
-  MEM_freeN(prwdgt->profile);
 }
 
 void profilewidget_free(ProfileWidget *prwdgt)
@@ -112,7 +111,6 @@ void profilewidget_free(ProfileWidget *prwdgt)
 #if DEBUG_PRWDGT
   printf("PROFILEWIDGET FREE\n");
 #endif
-
   if (prwdgt) {
     profilewidget_free_data(prwdgt);
     MEM_freeN(prwdgt);
@@ -126,11 +124,11 @@ void profilewidget_copy_data(ProfileWidget *target, const ProfileWidget *prwdgt)
 #endif
   *target = *prwdgt;
 
-  if (prwdgt->profile->path) {
-    target->profile->path = MEM_dupallocN(prwdgt->profile->path);
+  if (prwdgt->path) {
+    target->path = MEM_dupallocN(prwdgt->path);
   }
-  if (prwdgt->profile->table) {
-    target->profile->table = MEM_dupallocN(prwdgt->profile->table);
+  if (prwdgt->table) {
+    target->table = MEM_dupallocN(prwdgt->table);
   }
 }
 
@@ -141,9 +139,9 @@ ProfileWidget *profilewidget_copy(const ProfileWidget *prwdgt)
 #endif
 
   if (prwdgt) {
-    ProfileWidget *prwdgtn = MEM_dupallocN(prwdgt);
-    profilewidget_copy_data(prwdgtn, prwdgt);
-    return prwdgtn;
+    ProfileWidget *new_prdgt = MEM_dupallocN(prwdgt);
+    profilewidget_copy_data(new_prdgt, prwdgt);
+    return new_prdgt;
   }
   return NULL;
 }
@@ -151,7 +149,7 @@ ProfileWidget *profilewidget_copy(const ProfileWidget *prwdgt)
 /* ********** requires profilewidget_changed() call after ******** */
 
 /* remove specified point */
-bool profilepath_remove_point(ProfilePath *prpath, ProfilePoint *point)
+bool profilewidget_remove_point(ProfileWidget *prwdgt, ProfilePoint *point)
 {
   ProfilePoint *pts;
   int a, b, removed = 0;
@@ -161,16 +159,16 @@ bool profilepath_remove_point(ProfilePath *prpath, ProfilePoint *point)
 #endif
 
   /* must have 2 points minimum */
-  if (prpath->totpoint <= 2) {
+  if (prwdgt->totpoint <= 2) {
     return false;
   }
 
-  pts = MEM_mallocN((size_t)prpath->totpoint * sizeof(ProfilePoint), "path 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list