Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory issue when returing static Mesh within getConformingDelaunayTriangulation() #9

Open
ppizarror opened this issue Nov 25, 2022 · 1 comment

Comments

@ppizarror
Copy link

ppizarror commented Nov 25, 2022

Hi! I found another issue during triangulation.

If Delaunay is used consecutively, the mesh was already instantiated (because its singleton-pattern static). Thus, deleting its points and edges (calling our own .clear() method) generates a CxC000005 memory issue. This does not happen with Voronoi, as it does not return a static mesh.

Thus, instead of:

Mesh<Triangle> &TriangleDelaunayGenerator::getConformingDelaunayTriangulation() {
    if (!this->empty) {
        char switches[] = "pzejDQ";
        callTriangle(seedPoints, switches);
    }

    // Dangerous, even if the memory is not cleared, the mesh will not initialize again!
    static Mesh<Triangle> mesh = initializeMesh<Triangle>();
    return mesh;
}

The method returns:

Mesh<Triangle> &TriangleDelaunayGenerator::getConformingDelaunayTriangulation() {
    if (!this->empty) {
        char switches[] = "pzejDQ";
        callTriangle(seedPoints, switches);
    }
    if (this->meshInitialized) return this->mesh;
    this->mesh = initializeMesh<Triangle>();
    this->meshInitialized = true;
    return this->mesh;
}

Where this->mesh and this->meshInitialized class parameters, the problem is solved and works fantastic.

See https://github.com/IE3-CL/Delynoi for the updated version of this library.

@ppizarror
Copy link
Author

Also, I tested thoroughly using Valgrind and no warnings whatsoever!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant