[Bf-blender-cvs] [8a746714662] greasepencil-object: Fix memory leak and access violation

Antonio Vazquez noreply at git.blender.org
Mon May 8 12:53:52 CEST 2017


Commit: 8a7467146628632bbc6f834d56278af6a7e0c37b
Author: Antonio Vazquez
Date:   Mon May 8 12:53:36 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB8a7467146628632bbc6f834d56278af6a7e0c37b

Fix memory leak and access violation

The builtin shaders are free in blender close, so the engine must not free them. The memory leak was relatred to recreate the shaders again and again, so the free only use the last copy.

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

M	source/blender/draw/engines/gpencil/gpencil_engine.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index c8ffa53f608..c458675d7db 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -118,21 +118,26 @@ static void GPENCIL_engine_init(void *vedata)
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 
 	/* normal fill shader */
-	e_data.gpencil_fill_sh = DRW_shader_create(datatoc_gpencil_fill_vert_glsl, NULL,
-											   datatoc_gpencil_fill_frag_glsl,
-											   NULL);
-
+	if (!e_data.gpencil_fill_sh) {
+		e_data.gpencil_fill_sh = DRW_shader_create(datatoc_gpencil_fill_vert_glsl, NULL,
+			datatoc_gpencil_fill_frag_glsl,
+			NULL);
+	}
 	/* normal stroke shader using geometry to display lines */
-	e_data.gpencil_stroke_sh = DRW_shader_create(datatoc_gpencil_stroke_vert_glsl, 
-												 datatoc_gpencil_stroke_geom_glsl,
-												 datatoc_gpencil_stroke_frag_glsl,
-												 NULL);
-
+	if (!e_data.gpencil_stroke_sh) {
+		e_data.gpencil_stroke_sh = DRW_shader_create(datatoc_gpencil_stroke_vert_glsl,
+			datatoc_gpencil_stroke_geom_glsl,
+			datatoc_gpencil_stroke_frag_glsl,
+			NULL);
+	}
 	/* used for edit points or strokes with one point only */
-	e_data.gpencil_volumetric_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
-
+	if (!e_data.gpencil_volumetric_sh) {
+		e_data.gpencil_volumetric_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
+	}
 	/* used to filling during drawing */
-	e_data.gpencil_drawing_fill_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SMOOTH_COLOR);
+	if (!e_data.gpencil_drawing_fill_sh) {
+		e_data.gpencil_drawing_fill_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SMOOTH_COLOR);
+	}
 
 	if (!stl->storage) {
 		stl->storage = MEM_callocN(sizeof(GPENCIL_Storage), "GPENCIL_Storage");
@@ -144,8 +149,6 @@ static void GPENCIL_engine_free(void)
 {
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_fill_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_stroke_sh);
-	DRW_SHADER_FREE_SAFE(e_data.gpencil_volumetric_sh);
-	DRW_SHADER_FREE_SAFE(e_data.gpencil_drawing_fill_sh);
 }
 
 /* create shading group for filling */




More information about the Bf-blender-cvs mailing list