libriscv / godot-sandbox

In-editor scripting and sandboxing for Godot
https://libriscv.no/docs/intro
BSD 3-Clause "New" or "Revised" License
172 stars 8 forks source link

Too many arena chunks: Cannot handle expected amount of triangles. #217

Open fire opened 4 hours ago

fire commented 4 hours ago

std::vector<int> triangle_counts = {1000, 10000};

Let's assume I want to have between 100_000 triangles to 10_000_000 triangles.

The first one works, and the second one explodes

Exception: Too many arena chunks (data: fa0)

extern "C" Variant test_find_matches_closest_surface_logarithmic_load() {
    std::vector<int> triangle_counts = {10000};
    bool all_tests_passed = true;

    for (int count : triangle_counts) {
        Eigen::MatrixXd source_vertices = Eigen::MatrixXd::Zero(count * 3, 3);
        Eigen::MatrixXi source_triangles = Eigen::MatrixXi::Zero(count, 3);
        Eigen::MatrixXd source_normals = Eigen::MatrixXd::Zero(count * 3, 3);
        Eigen::MatrixXd source_weights = Eigen::MatrixXd::Zero(count * 3, 2);

        for (int i = 0; i < count; ++i) {
            source_vertices.row(i * 3) << i, 0, 0;
            source_vertices.row(i * 3 + 1) << i + 1, 0, 0;
            source_vertices.row(i * 3 + 2) << i, 1, 0;

            source_triangles.row(i) << i * 3, i * 3 + 1, i * 3 + 2;

            source_normals.row(i * 3) << 0, 0, 1;
            source_normals.row(i * 3 + 1) << 0, 0, 1;
            source_normals.row(i * 3 + 2) << 0, 0, 1;

            source_weights.row(i * 3) << 1, 0;
            source_weights.row(i * 3 + 1) << 0, 1;
            source_weights.row(i * 3 + 2) << 0.5, 0.5;
        }

        Eigen::MatrixXd target_vertices(2, 3);
        target_vertices << 0.1, 0.1, 0,
                           count, count, count;
        Eigen::MatrixXi target_triangles(1, 3);
        target_triangles << 0, 1;
        Eigen::MatrixXd target_normals(2, 3);
        target_normals << 0, 0, 1,
                          1, 0, 0;

        double distance_threshold_squared = 0.5;
        double angle_threshold_degrees = 10;

        Eigen::VectorXi expected_matched(2);
        expected_matched << 1, 0;

        Eigen::MatrixXd target_weights;
        Eigen::Array<bool, Eigen::Dynamic, 1> matched;
        find_matches_closest_surface(source_vertices, source_triangles, source_normals, target_vertices, target_triangles, target_normals,
                                     source_weights, distance_threshold_squared, angle_threshold_degrees, target_weights, matched);
        std::cout << "Triangle Count: " << count << std::endl;
        std::cout << "Target Matched:\n" << matched << std::endl;
        std::cout << "Expected Matched:\n" << expected_matched << std::endl;
        if (!matched.cast<int>().isApprox(expected_matched.cast<int>())) {
            all_tests_passed = false;
            break;
        }
    }

    return all_tests_passed;
}
fire commented 3 hours ago

Maybe make the limit adjustable as a property?