Can someone pls help with procedural mesh creation in c++

So I have this code inside of a Actor:

Model *model = Content::CreateVirtualAsset<Model>();

const int32* meshesCountPerLod = new int32[1]{ 1 };
Span<int32> spanMeshesCountPerLod(meshesCountPerLod, sizeof(int32));
model->SetupLODs(spanMeshesCountPerLod);

Mesh& mesh = model->LODs[0].Meshes[0];

VB0ElementType* vb0 = new VB0ElementType[3]{ VB0ElementType{Vector3(-1,0,0)}, VB0ElementType{Vector3(0,1,0)}, VB0ElementType{Vector3(1,0,0)} };

Array<VB1ElementType> vb1;
Array<VB2ElementType> vb2;

vb1.Resize(3);

const auto n = Float1010102(Vector3::UnitZ);
const auto t = Float1010102(Vector3::UnitX);

for (uint32 i = 0; i < 3; i++)
{
    vb1[i].Normal = n;
    vb1[i].Tangent = t;
}

auto v = Half2(0, 0);

for (uint32 i = 0; i < 3; i++) {
    vb1[i].TexCoord = v;
}

{
    auto v = Half2(0, 0);

    for (uint32 i = 0; i < 3; i++)
        vb1[i].LightmapUVs = v;
}

uint32* ib = new uint32[3]{ 0,1,2 };

mesh.UpdateMesh(3, 1, vb0, vb1.Get(), vb2.HasItems() ? vb2.Get() : nullptr, ib);

auto result = New<StaticModel>();
result->Model = model;
result->SetLocalScale(Vector3(100));
result->SetParent(this);

It should spawn a Triangle, but instead crashes the window :confused:

(UPDATE)

Fixed some bugs in code. Still a crash.

vv

(UPDATE 2) Happens here

void ScriptingObject::RegisterObject()

{

ASSERT(!IsRegistered());

Flags |= ObjectFlags::IsRegistered;

Scripting::RegisterObject(this);

}

In which Actor method you call it? Like OnEnable /OnBeginPlay? Do you call base class of the overridden Actor type (eg. Actor::OnBeginPlay())?

In constructor. I think thats the issue.