local variables used to create mesh... kaboom?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kjkrum
Posts: 26
Joined: Wed Oct 29, 2003 5:34 pm

local variables used to create mesh... kaboom?

Post by kjkrum »

Say this code is in a function:

Code: Select all

core::vector3df v0 = core::vector3df(-1, 1, -1);
// other vectors
SMeshBuffer* buffer = new SMeshBuffer();
buffer->Vertices.push_back(video::S3DVertex(v0, n0, clr, t0));
// other vertices
SMesh* mesh = new SMesh;
mesh->addMeshBuffer(buffer);
// blah blah
return mesh;
Note that in the first line, v0 is local. Is this gonna blow up because v0 is on the stack, or does it get copied?
pippy3
Posts: 155
Joined: Tue Dec 15, 2009 7:32 am

Post by pippy3 »

video::S3DVertex will copy the vertex into it.

If you lookin the API, you'll see this:

Code: Select all

core::vector3df 	Pos
That means that there's a position inside video::S3DVertex.

If it was this:

Code: Select all

core::vector3df* Pos
It would point to your vector, and when the function was over the vector would be deleted. Irrlicht is well written and you'll never come across this.
kjkrum
Posts: 26
Joined: Wed Oct 29, 2003 5:34 pm

Post by kjkrum »

Awesome, thanks.
Post Reply