Important to know when working with shared_ptr is that once it holds an object you must adjust the interface of functions to replace a Mesh* with shared_ptr<Mesh> too when it internally expects a shared_ptr because otherwise you confuse the reference counter and get a dangling pointer in the calling instance. But this will likely cause a crash and not an empty mesh.
Example:
Code: Select all
class Mesh
{
public:
Mesh()
{
i=0;
}
~Mesh()
{
}
void func()
{
i++;
}
private:
int i;
};
void useMesh(Mesh* p)
{
std::shared_ptr<Mesh> u(p);
u->func();
} // <<== here the Test object will be destroyed
int main()
{
std::shared_ptr<Mesh> t(new Mesh);
Mesh*p = t.get();
useMesh(p);
Mesh*q = t.get(); // <<== t holds a dangling pointer now
q->func();
}
Last weekend I was also working to improve the Netgen cmake checks and therefore had to try netgen v6. I made the same experience that the mesh is empty and stumbled across the same issue as you. For testing purposes I added an "exit(0);" at this code bloc but FreeCAD didn't terminate. So, this means the code part is never executed and there must be other reasons for the empty mesh.