Browse Source

Merge pull request #47187 from lawnjelly/ewok_poly_protection

Batching - add protection against invalid polys
Rémi Verschelde 4 years ago
parent
commit
f31523a99e
1 changed files with 17 additions and 1 deletions
  1. 17 1
      drivers/gles_common/rasterizer_canvas_batcher.h

+ 17 - 1
drivers/gles_common/rasterizer_canvas_batcher.h

@@ -1547,8 +1547,9 @@ bool C_PREAMBLE::_prefill_polygon(RasterizerCanvas::Item::CommandPolygon *p_poly
 	int num_inds = p_poly->indices.size();
 
 	// nothing to draw?
-	if (!num_inds)
+	if (!num_inds || !p_poly->points.size()) {
 		return false;
+	}
 
 	// we aren't using indices, so will transform verts more than once .. less efficient.
 	// could be done with a temporary vertex buffer
@@ -1675,6 +1676,13 @@ bool C_PREAMBLE::_prefill_polygon(RasterizerCanvas::Item::CommandPolygon *p_poly
 
 			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
 			if (software_transform) {
 				Vector2 pos = p_poly->points[ind];
@@ -1815,6 +1823,14 @@ PREAMBLE(bool)::_software_skin_poly(RasterizerCanvas::Item::CommandPolygon *p_po
 		int ind = p_poly->indices[n];
 
 		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];
 		bvs[n].pos.set(pos.x, pos.y);