From ae1c45329d44a5f834dffb9862224ca8b003a252 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Sat, 20 Mar 2021 10:23:43 +0000 Subject: [PATCH] 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. --- .../gles_common/rasterizer_canvas_batcher.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/gles_common/rasterizer_canvas_batcher.h b/drivers/gles_common/rasterizer_canvas_batcher.h index fce51a72895..61622bac9c6 100644 --- a/drivers/gles_common/rasterizer_canvas_batcher.h +++ b/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(); // 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 @@ -1667,6 +1668,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]; @@ -1807,6 +1815,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);