0
$\begingroup$

Pretty much the title I am trying to delete a few faces of a mesh using open mesh, like this:


    MyMesh mesh;

    char fname[1024];
    sprintf(fname, "box_%i.obj", 0);
    if (!OpenMesh::IO::read_mesh(mesh, std::string(fname)))
    {
        std::cerr << "read error\n";
        exit(1);
    }

    MyMesh::FaceIter v_it, v_end(mesh.faces_end());
    uint count = 0;
    for (v_it=mesh.faces_begin(); v_it!=v_end; ++v_it)
    {
        mesh.delete_face(*v_it, true);
    }

This is segfaulting on the first call to delete_face.

However, writing this mesh (without trying to delete faces):

    if (!OpenMesh::IO::write_mesh(mesh, std::string("open_mesh.obj")))
    {
        std::cerr << "write error\n";
        exit(1);
    }

Works perfectly fine and blender can open the obj. So the issue very much seems to be with how I am trying to delete the faces.

$\endgroup$
2
  • $\begingroup$ I don't think you can delete it like that, you're probably get a similar issue to the one you would have if you removed an element from a std::list via iterator in a for loop. Try to collect the iterators related in a std::list or std::vector, iterate through those for deletion and see what happens. $\endgroup$ Mar 10, 2022 at 10:46
  • $\begingroup$ Or I guess you can also do a similar loop (pseudocode): while(mesh.numFaces > 0) { mesh.delete(mesh.faces_begin(),true)); } $\endgroup$ Mar 10, 2022 at 10:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy