[Bf-blender-cvs] [6b794565aa0] blender2.8: Fix crash with DispLists without vertices

Germano noreply at git.blender.org
Thu Dec 14 17:31:57 CET 2017


Commit: 6b794565aa0658bafff40491cad05c01d1d65000
Author: Germano
Date:   Thu Dec 14 14:31:08 2017 -0200
Branches: blender2.8
https://developer.blender.org/rB6b794565aa0658bafff40491cad05c01d1d65000

Fix crash with DispLists without vertices

Wee must return VertBuffers even when its size is zero

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

M	source/blender/draw/intern/draw_cache_impl_curve.c
M	source/blender/draw/intern/draw_cache_impl_displist.c
M	source/blender/draw/intern/draw_cache_impl_metaball.c

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

diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index 8e38e22a210..42533cc2802 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -813,13 +813,11 @@ static Gwn_Batch *curve_batch_cache_get_pos_and_normals(CurveRenderData *rdata,
 		if (cache->surface.verts == NULL) {
 			cache->surface.verts = DRW_displist_vertbuf_calc_pos_with_normals(lb);
 		}
-		if (cache->surface.verts) {
-			if (cache->surface.triangles_in_order == NULL) {
-				cache->surface.triangles_in_order = DRW_displist_indexbuf_calc_triangles_in_order(lb);
-			}
-			cache->surface.batch = GWN_batch_create_ex(
-			        GWN_PRIM_TRIS, cache->surface.verts, cache->surface.triangles_in_order, 0);
+		if (cache->surface.triangles_in_order == NULL) {
+			cache->surface.triangles_in_order = DRW_displist_indexbuf_calc_triangles_in_order(lb);
 		}
+		cache->surface.batch = GWN_batch_create_ex(
+		        GWN_PRIM_TRIS, cache->surface.verts, cache->surface.triangles_in_order, 0);
 	}
 
 	return cache->surface.batch;
@@ -1051,8 +1049,9 @@ Gwn_Batch **DRW_curve_batch_cache_get_surface_shaded(
 		}
 
 		for (int i = 0; i < gpumat_array_len; ++i) {
-			cache->surface.shaded_triangles[i] = GWN_batch_create(
-			        GWN_PRIM_TRIS, cache->surface.verts, el[i]);
+			cache->surface.shaded_triangles[i] = GWN_batch_create_ex(
+			        GWN_PRIM_TRIS, cache->surface.verts, el[i], GWN_BATCH_OWNS_INDEX);
+
 			/* TODO: Add vertbuff for UV */
 		}
 
diff --git a/source/blender/draw/intern/draw_cache_impl_displist.c b/source/blender/draw/intern/draw_cache_impl_displist.c
index 87ff52c951c..33c4a938a56 100644
--- a/source/blender/draw/intern/draw_cache_impl_displist.c
+++ b/source/blender/draw/intern/draw_cache_impl_displist.c
@@ -121,9 +121,6 @@ static void displist_indexbufbuilder_set(Gwn_IndexBufBuilder *elb, const DispLis
 Gwn_VertBuf *DRW_displist_vertbuf_calc_pos_with_normals(ListBase *lb)
 {
 	const int tri_len = curve_render_surface_tri_len_get(lb);
-	if (tri_len == 0) {
-		return NULL;
-	}
 
 	static Gwn_VertFormat format = { 0 };
 	static struct { uint pos, nor; } attr_id;
@@ -191,16 +188,11 @@ Gwn_IndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(ListBase *lb)
 
 Gwn_IndexBuf **DRW_displist_indexbuf_calc_triangles_in_order_split_by_material(ListBase *lb, uint gpumat_array_len)
 {
-	const int tri_len = curve_render_surface_tri_len_get(lb);
-	if (tri_len == 0) {
-		return NULL;
-	}
-
-	const int vert_len = curve_render_surface_vert_len_get(lb);
-
 	Gwn_IndexBuf **shaded_triangles_in_order = MEM_callocN(sizeof(*shaded_triangles_in_order) * gpumat_array_len, __func__);
+	const int tri_len = curve_render_surface_tri_len_get(lb);
 
-	{
+	if (tri_len != 0) {
+		const int vert_len = curve_render_surface_vert_len_get(lb);
 		int i;
 		Gwn_IndexBufBuilder *elb = BLI_array_alloca(elb, gpumat_array_len);
 
diff --git a/source/blender/draw/intern/draw_cache_impl_metaball.c b/source/blender/draw/intern/draw_cache_impl_metaball.c
index 762564cc2a5..9a9bbbd2c0c 100644
--- a/source/blender/draw/intern/draw_cache_impl_metaball.c
+++ b/source/blender/draw/intern/draw_cache_impl_metaball.c
@@ -134,13 +134,11 @@ Gwn_Batch *DRW_metaball_batch_cache_get_triangles_with_normals(Object *ob)
 	if (cache->batch == NULL) {
 		ListBase *lb = &ob->curve_cache->disp;
 		Gwn_VertBuf *verts = DRW_displist_vertbuf_calc_pos_with_normals(lb);
-		if (verts) {
-			cache->batch = GWN_batch_create_ex(
-			        GWN_PRIM_TRIS,
-			        verts,
-			        DRW_displist_indexbuf_calc_triangles_in_order(lb),
-			        GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
-		}
+		cache->batch = GWN_batch_create_ex(
+		        GWN_PRIM_TRIS,
+		        verts,
+		        DRW_displist_indexbuf_calc_triangles_in_order(lb),
+		        GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
 	}
 
 	return cache->batch;



More information about the Bf-blender-cvs mailing list