Help using netgen library to define simple Mesh using plain C++

Hello I am trying to understand how create simple meshes using only C++. All the tutorials that I found use python but I need plain C++.

An example of this tutorial in C++ would be awesome:
https://docu.ngsolve.org/v6.2.2204/i-tutorials/unit-4.3-manualmesh/manualmeshing.html#Two-dimensional-meshes

I am trying to reverse engineer it but I am having problem adding the Facedescriptors. In particular I get an access violation exception with the following code:

using namespace netgen;
Mesh mesh = Mesh();
FaceDescriptor fd(1, 1, 0, 1);
mesh.AddFaceDescriptor(fd);

Can you help me finding the problem?

Thanks,
Stenio

I think I’ve found the root of the problem: after the creation of the object FaceDescriptor the private member bcname is null, but from the source code it should be the string “default”. That is causing the exception problem on the assignement of the object.
I tried also to explicitly set the member calling SetBCName but it is still null after the call. :woozy_face:

Example code based on AddRegion method of python_mesh.cpp:

Mesh mesh;
mesh.SetDimension(2);
int dims = mesh.GetDimension();
int dim = 2;
auto& regionnames = mesh.GetRegionNamesCD(dims - dim);
string regionName = "material";
regionnames.Append(&regionName);
int idx = regionnames.Size();
if (dim == 2) {
    FaceDescriptor fd;
    fd.SetBCName(regionnames.Last());
    fd.SetBCProperty(idx);
    mesh.AddFaceDescriptor(fd);
}