trouble with drawing simple triangle

i want to draw simple triangle so i read the manual and wrote this code:

PT(GeomTriangles) prim;
PT(GeomVertexData) vdata;

vdata = new GeomVertexData("trinagles", GeomVertexFormat::get_v3t2() , Geom::UH_static);

GeomVertexWriter vertex, texcoord;

	
vertex = GeomVertexWriter(vdata, "vertex");
texcoord = GeomVertexWriter(vdata, "texcoord");

vertex.add_data3f(1, 0, 0);
texcoord.add_data2f(1, 0);
 
vertex.add_data3f(1, 1, 0);
texcoord.add_data2f(1, 1);
 
vertex.add_data3f(0, 1, 0);
texcoord.add_data2f(0, 1);
 
vertex.add_data3f(0, 0, 0);
texcoord.add_data2f(0, 0);

prim = new GeomTriangles(Geom::UH_static);

prim->add_vertex(0);
prim->add_vertex(1);
prim->add_vertex(2);
prim->close_primitive();
PT(Geom) geom(new Geom(vdata));
geom->add_primitive(prim);

PT(GeomNode) gNode(new GeomNode("gNode"));
cout<<"is_null: "      <<gNode.is_null()<<endl;
cout<<"gNode's name: " <<gNode->get_name()<<endl;
/***********************
gNode->add_geom(geom);

NodePath nodePath = window->get_render().attach_new_node(gNode);
    /***********************

the program flew (exited) with the following information:

Unhandled exception at 0x011ebe98 in panda test 3.exe: 0xC0000005: Access violation writing location 0x00b135b0.

when i’m removing the part inside the asterisks
the program run properly, but , of course, without the triangle.

thank you all.

I just copy/pasted your code into VS and it works fine in debug mode but crashes in release mode.

I don’t see anything obviously wrong in the code, but can you get other projects to work? It’s a common mistake to use MSVS2010 instead of MSVS2008, or to have some project settings set incorrectly, particularly trying to build in debug mode, for instance, or building in release mode but failing to remove NDEBUG from the project settings. Making any of these mistakes can cause any Panda code to crash in mysterious ways.

David

than you very much david!!!
the NDEBUG was the problem.

Thanks David!!

I am new to panda3d and try to make my first game ever in C++

My tool is MSVC2008 for panda because I made already 2 programs in C++ (MFC) with thousends of functions each

I have removed NDEBUG and all problems are solved!

Because many starters have the same problems because there is not a single MSVC2008 project found for panda3d, I like to post a simple MSVC2008 project for starters with the correct settings and libraries.

Do you think this is a good idea?

Peter

Sure, that does sound like a great idea.

David

David,

I made the Hello World sample for panda, how and where should I post the zip file?

Filesize 8Kb.

Peter