GeomNode::add_geom crashes

Hi. I am trying to create some dynamic geometry with c++. As a simple test, I have started to adapt the cube example like the following:

#include <panda3d/pandaFramework.h>
#include <panda3d/geomTriangles.h>
#include <panda3d/geomPoints.h>
#include <panda3d/pandaSystem.h>


int main(int argc, char *argv[]) {
	// Open the framework
	PandaFramework framework;
	framework.open_framework(argc, argv);
	// Set a nice title
	framework.set_window_title("Panda Garten");
	// Open it!
	WindowFramework *window = framework.open_window();

	// Check whether the window is loaded correctly
	if (window != nullptr) {
		nout << "Opened the window successfully!\n";

		window->enable_keyboard(); // Enable keyboard detection
		window->setup_trackball(); // Enable default camera movement

		// Put here your own code, such as the loading of your models
		window->enable_keyboard();

		GeomVertexData geomData("particles", GeomVertexFormat::get_v3(), GeomEnums::UH_dynamic);
		auto vertex = GeomVertexWriter(&geomData, "vertex");
		vertex.add_data3f({-1, -1, -1});
		vertex.add_data3f({1, 1, -1});
		vertex.add_data3f({1, 1, 1});
		vertex.add_data3f({-1, -1, 1});

		auto tris = GeomTriangles(Geom::UH_dynamic);
		tris.add_vertices(0, 1, 3);
		tris.add_vertices(1, 2, 3);

		Geom geom(&geomData);
		geom.add_primitive(&tris);

		GeomNode geomNode("cubes");
		geomNode.add_geom(&geom);

		window->get_render().attach_new_node(&geomNode);

		// Do the main loop
		framework.main_loop();
	} else {
		nout << "Could not load the window!\n";
	}
	// Close the framework
	framework.close_framework();
	return 0;
}

This compiles fine and opens a window. But the line geom.add_primitive causes an invalid assertion.

dtool/src/dtoolbase/typeHandle.cxx:78: void TypeHandle::dec_memory_usage(TypeHandle::MemoryClass, size_t): Assertion `rnode->_memory_usage[memory_class] >= 0’ failed.

This is the stacktrace
image

I use the following cmake code to compile the project:

cmake_minimum_required(VERSION 3.15)

project(pandagarten)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

find_package(Eigen3)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

add_executable(pandagarten main.cpp)
target_link_directories(pandagarten PUBLIC /usr/lib/panda3d)
target_link_libraries(pandagarten
        Eigen3::Eigen
        Threads::Threads

        p3dtoolconfig
        p3dtool
        pandagl
        p3framework
        panda
        #           pandafx
        pandaexpress
        #           pandaphysics
        p3pystub
        p3direct
        )

My system is an up to date arch linux. The dynamic mesh python sample seems to work just fine.

Anyone have an idea what might be going on?

OK, got it now. I had to create a PT

            PT(GeomTriangles) tris;
	tris = new GeomTriangles(Geom::UH_dynamic);
	tris->add_vertices(0, 1, 3);
	tris->add_vertices(1, 2, 3);

	Geom geom(&geomData);
	geom.add_primitive(tris);