[Bf-blender-cvs] [be20f17] soc-2016-pbvh-painting: Alloc'd/free'd a stroke cache in both vertex and weight paint toggles.

Nathan Vollmer noreply at git.blender.org
Fri May 27 06:03:01 CEST 2016


Commit: be20f17de4cb288f7cc5041808b2d901f9924120
Author: Nathan Vollmer
Date:   Thu May 26 22:02:45 2016 -0600
Branches: soc-2016-pbvh-painting
https://developer.blender.org/rBbe20f17de4cb288f7cc5041808b2d901f9924120

Alloc'd/free'd a stroke cache in both vertex and weight paint toggles.

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

M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h

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

diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index ea131f1..73b2fb4 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -1771,6 +1771,13 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op)
 		ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e');
 		ED_mesh_mirror_topo_table(NULL, NULL, 'e');
 
+
+		/* If the cache is not released by a cancel or a done, free it now. */
+		if (ob->sculpt->cache){
+			sculpt_cache_free(ob->sculpt->cache);
+			ob->sculpt->cache = NULL;
+		}
+
 		BKE_sculptsession_free(ob);
 
 		paint_cursor_delete_textures();
@@ -1794,6 +1801,10 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op)
 			BKE_sculptsession_free(ob);
 
 		vertex_paint_init_session(scene, ob);
+
+		/* Cache needs to be initialized before mesh_build_data is called. */
+		ob->sculpt->cache = MEM_callocN(sizeof(StrokeCache), "stroke cache");
+
 	}
 	
 	/* Weightpaint works by overriding colors in mesh,
@@ -2546,6 +2557,12 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
 			BKE_mesh_flush_select_from_polys(me);
 		}
 
+		/* If the cache is not released by a cancel or a done, free it now. */
+		if (ob->sculpt->cache){
+			sculpt_cache_free(ob->sculpt->cache);
+			ob->sculpt->cache = NULL;
+		}
+
 		BKE_sculptsession_free(ob);
 
 		paint_cursor_delete_textures();
@@ -2569,6 +2586,9 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
 			BKE_sculptsession_free(ob);
 
 		vertex_paint_init_session(scene, ob);
+
+		/* Cache needs to be initialized before mesh_build_data is called. */
+		ob->sculpt->cache = MEM_callocN(sizeof(StrokeCache), "stroke cache");
 	}
 	
 	/* update modifier stack for mapping requirements */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 8723c9b..ec2f029 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3842,7 +3842,7 @@ static const char *sculpt_tool_name(Sculpt *sd)
  * Operator for applying a stroke (various attributes including mouse path)
  * using the current brush. */
 
-static void sculpt_cache_free(StrokeCache *cache)
+void sculpt_cache_free(StrokeCache *cache)
 {
 	if (cache->dial)
 		MEM_freeN(cache->dial);
@@ -3885,7 +3885,7 @@ static void sculpt_init_mirror_clipping(Object *ob, SculptSession *ss)
 /* Initialize the stroke cache invariants from operator properties */
 static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSession *ss, wmOperator *op, const float mouse[2])
 {
-	StrokeCache *cache = MEM_callocN(sizeof(StrokeCache), "stroke cache");
+	StrokeCache *cache;
 	Scene *scene = CTX_data_scene(C);
 	UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings;
 	Brush *brush = BKE_paint_brush(&sd->paint);
@@ -3897,7 +3897,14 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio
 	int i;
 	int mode;
 
-	ss->cache = cache;
+	// VW paint needs to allocate stroke cache before update is called.
+	if (!ss->cache) {
+		cache = MEM_callocN(sizeof(StrokeCache), "stroke cache");
+		ss->cache = cache;
+	}
+	else {
+		cache = ss->cache;
+	}
 
 	/* Set scaling adjustment */
 	if (brush->sculpt_tool == SCULPT_TOOL_LAYER) {
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index ca7b5a1..0fe442f 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -219,6 +219,8 @@ typedef struct StrokeCache {
 	rcti current_r; /* current redraw rectangle */
 } StrokeCache;
 
+void sculpt_cache_free(StrokeCache *cache);
+
 SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType type);
 SculptUndoNode *sculpt_undo_get_node(PBVHNode *node);
 void sculpt_undo_push_begin(const char *name);




More information about the Bf-blender-cvs mailing list