Jelajahi Sumber

Batching - add protection against invalid polys

The editor under certain circumstances is passing invalid polys to the renderer. This should be fixed upstream but just in case this PR adds fault tolerance for invalid indices.
lawnjelly 4 tahun lalu
induk
melakukan
ae1c45329d
1 mengubah file dengan 17 tambahan dan 1 penghapusan
  1. 17 1
      drivers/gles_common/rasterizer_canvas_batcher.h

+ 17 - 1
drivers/gles_common/rasterizer_canvas_batcher.h

@@ -1539,8 +1539,9 @@ bool C_PREAMBLE::_prefill_polygon(RasterizerCanvas::Item::CommandPolygon *p_poly
 	int num_inds = p_poly->indices.size();
 	int num_inds = p_poly->indices.size();
 
 
 	// nothing to draw?
 	// nothing to draw?
-	if (!num_inds)
+	if (!num_inds || !p_poly->points.size()) {
 		return false;
 		return false;
+	}
 
 
 	// we aren't using indices, so will transform verts more than once .. less efficient.
 	// we aren't using indices, so will transform verts more than once .. less efficient.
 	// could be done with a temporary vertex buffer
 	// could be done with a temporary vertex buffer
@@ -1667,6 +1668,13 @@ bool C_PREAMBLE::_prefill_polygon(RasterizerCanvas::Item::CommandPolygon *p_poly
 
 
 			RAST_DEV_DEBUG_ASSERT(ind < p_poly->points.size());
 			RAST_DEV_DEBUG_ASSERT(ind < p_poly->points.size());
 
 
+			// recover at runtime from invalid polys (the editor may send invalid polys)
+			if ((unsigned int)ind >= (unsigned int)num_verts) {
+				// will recover as long as there is at least one vertex.
+				// if there are no verts, we will have quick rejected earlier in this function
+				ind = 0;
+			}
+
 			// this could be moved outside the loop
 			// this could be moved outside the loop
 			if (software_transform) {
 			if (software_transform) {
 				Vector2 pos = p_poly->points[ind];
 				Vector2 pos = p_poly->points[ind];
@@ -1807,6 +1815,14 @@ PREAMBLE(bool)::_software_skin_poly(RasterizerCanvas::Item::CommandPolygon *p_po
 		int ind = p_poly->indices[n];
 		int ind = p_poly->indices[n];
 
 
 		RAST_DEV_DEBUG_ASSERT(ind < num_verts);
 		RAST_DEV_DEBUG_ASSERT(ind < num_verts);
+
+		// recover at runtime from invalid polys (the editor may send invalid polys)
+		if ((unsigned int)ind >= (unsigned int)num_verts) {
+			// will recover as long as there is at least one vertex.
+			// if there are no verts, we will have quick rejected earlier in this function
+			ind = 0;
+		}
+
 		const Point2 &pos = pTemps[ind];
 		const Point2 &pos = pTemps[ind];
 		bvs[n].pos.set(pos.x, pos.y);
 		bvs[n].pos.set(pos.x, pos.y);