Unit test to check for crashes in rasterizing long, skinny triangles

Specifically, when rasterizing a triangle into a heightfield with width or height of 0.  This can happen when the input geometry bounding box extents are less than half the cell size in either x or z.  This is a degenerate case, but can crop up in real life scenarios (see https://github.com/godotengine/godot/issues/65764) so we should at least ensure it doesn't crash here.
This commit is contained in:
Graham Pentheny 2022-11-25 19:55:38 -05:00
parent 3901c5854c
commit 4fef044660

View File

@ -694,6 +694,73 @@ TEST_CASE("rcRasterizeTriangle overlapping bb but non-overlapping triangle")
}
}
TEST_CASE("rcRasterizeTriangle smaller than half a voxel size in x")
{
SECTION("Skinny triangle along x axis")
{
rcContext ctx;
float verts[] = {
5, 0, 0.005f,
5, 0, -0.005f,
-5, 0, 0.005f,
-5, 0, 0.005f,
5, 0, -0.005f,
-5, 0, -0.005f,
};
float bmin[3];
float bmax[3];
rcCalcBounds(verts, 3, bmin, bmax);
float cellSize = 1;
float cellHeight = 1;
int width;
int height;
rcCalcGridSize(bmin, bmax, cellSize, &width, &height);
rcHeightfield solid;
REQUIRE(rcCreateHeightfield(&ctx, solid, width, height, bmin, bmax, cellSize, cellHeight));
unsigned char areas[] = {42, 42};
int flagMergeThr = 1;
REQUIRE(rcRasterizeTriangles(&ctx, verts, areas, 2, solid, flagMergeThr));
}
SECTION("Skinny triangle along z axis")
{
rcContext ctx;
float verts[] = {
0.005f, 0, 5,
-0.005f, 0, 5,
0.005f, 0, -5,
0.005f, 0, -5,
-0.005f, 0, 5,
-0.005f, 0, -5
};
float bmin[3];
float bmax[3];
rcCalcBounds(verts, 3, bmin, bmax);
float cellSize = 1;
float cellHeight = 1;
int width;
int height;
rcCalcGridSize(bmin, bmax, cellSize, &width, &height);
rcHeightfield solid;
REQUIRE(rcCreateHeightfield(&ctx, solid, width, height, bmin, bmax, cellSize, cellHeight));
unsigned char areas[] = {42, 42};
int flagMergeThr = 1;
REQUIRE(rcRasterizeTriangles(&ctx, verts, areas, 2, solid, flagMergeThr));
}
}
TEST_CASE("rcRasterizeTriangles")
{
rcContext ctx;