Files
third_party_meshoptimizer/tools/simplifyfuzz.cpp
T
Arseny Kapoulkine 59557e6607 tools: Add simplifyfuzz to stress test simplifier
The code for classifying topology and using the resulting data is
getting a little more complicated and critical than it used to be; while
we can test it on a wide set of meshes with various strange topology, it
would also help to be able to fuzz it.

We build a vertex buffer that will occasionally have redundancy in it
due to random collisions, which will generate seam/locked vertices, and
use the rest of the fuzz input as an index buffer.
2024-09-19 13:33:52 -07:00

39 lines
972 B
C++

#include "../src/meshoptimizer.h"
#include <float.h>
#include <stdint.h>
#include <stdlib.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* buffer, size_t size)
{
if (size == 0)
return 0;
srand(buffer[0]);
float vb[100][4];
for (int i = 0; i < 100; ++i)
{
vb[i][0] = rand() % 10;
vb[i][1] = rand() % 10;
vb[i][2] = rand() % 10;
vb[i][3] = rand() % 10;
}
unsigned int ib[999];
int indices = (size - 1) < 999 ? (size - 1) / 3 * 3 : 999;
for (int i = 0; i < indices; ++i)
ib[i] = buffer[1 + i] % 100;
unsigned int res[999];
meshopt_simplify(res, ib, indices, vb[0], 100, sizeof(float) * 4, 0, 1e-1f, 0, NULL);
meshopt_simplify(res, ib, indices, vb[0], 100, sizeof(float) * 4, 0, FLT_MAX, 0, NULL);
meshopt_simplify(res, ib, indices, vb[0], 100, sizeof(float) * 4, 0, FLT_MAX, meshopt_SimplifyLockBorder, NULL);
meshopt_simplify(res, ib, indices, vb[0], 100, sizeof(float) * 4, 0, FLT_MAX, meshopt_SimplifySparse, NULL);
return 0;
}