[SOLVED]OctreeSceneNode crashes

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Gtoknu
Posts: 9
Joined: Sat Sep 11, 2010 12:51 am

[SOLVED]OctreeSceneNode crashes

Post by Gtoknu »

Hello ppl!

k, I'm having trouble and i couldn't figure out what's causing it.

When I create a MeshScene and pass my Mesh trough it, works fine.
But if I try to create a OctreeScene and pass my Mesh trough it, the program crash.

Here's the point:

Code: Select all

        scene::IMeshSceneNode* mesh;
	mesh = smgr->addMeshSceneNode(mapa.getMesh()); // Works fine and I can see the mesh

Code: Select all

	scene::IMeshSceneNode* mesh;
	mesh = smgr->addOctreeSceneNode(mapa.getMesh()); // crash at this line, the debugger just says acess violation.
At the debugger, all the vars addresses look like 0x000000 and 0xcccccc, but if i mark a breakpoint there with a normal mesh, it goes fine, and all addresses and values will be ok.

I really need to know why this isn't working. I'm working on a maps, so, use octree is essential, since the maps polys are within 1k~600k :D

Thanks!
Last edited by Gtoknu on Thu Sep 30, 2010 6:11 pm, edited 1 time in total.
RuggJack93
Posts: 39
Joined: Mon Sep 06, 2010 5:09 pm
Location: Italy

Post by RuggJack93 »

I belive with Octrees the right procedure is this (from the tuts):

Code: Select all

 scene::IAnimatedMesh* mesh = smgr->getMesh("yourmesh");

scene::ISceneNode* node = smgr->addOctreeSceneNode(mesh->getMesh(0));
or in your case:

Code: Select all

scene::IMeshSceneNode* mesh; 
   mesh = smgr->addOctreeSceneNode(mapa.getMesh(0)); 
Maybe you've missed that "0" in getMesh()?
Gtoknu
Posts: 9
Joined: Sat Sep 11, 2010 12:51 am

Post by Gtoknu »

I didn't.

And, if you're wondering what mapa is, it's a class which load my map and store all the vertices and indices at a SMesh. getMesh() return the single SMesh that I have there.

Code: Select all

   scene::SMesh* mapMesh;
   //...
   scene::SMesh* getMesh();

Code: Select all

scene::SMesh* Map::getMesh()
{
	return this->mapMesh;
}
[/code]
RuggJack93
Posts: 39
Joined: Mon Sep 06, 2010 5:09 pm
Location: Italy

Post by RuggJack93 »

Sorry, i'm not very expert on SMeshes :oops:. Maybe the example 023 SMeshBufferHandling can help you, take a look at it.

I've tested it changing the original code from:

Code: Select all

// Add the mesh to the scene graph
	IMeshSceneNode* meshnode = smgr ->addMeshSceneNode(mesh.Mesh);
to

Code: Select all

// Add the mesh to the scene graph
	IMeshSceneNode* meshnode = smgr ->addOctreeSceneNode(mesh.Mesh);
and it worked fine.
Gtoknu
Posts: 9
Joined: Sat Sep 11, 2010 12:51 am

Post by Gtoknu »

It worked fine for me too...

Maybe it's the way that i'm making the vertices?

Take a look:

I allocate the buffers;

Code: Select all

	S3DVertex* vertices = new S3DVertex[65536+1];
	u16* indexList = new u16[65536*2+1];
Then i read my file;

make 2 counters;

Code: Select all

	u32 act1 = 0;
	u32 act2 = -1;
and start to add the vertices. When the vertices of the current meshbuffer exceeds 65536(maxvertex), it add that buffer to the main mesh and make another meshbuffer and start it over again...

Code: Select all

	for(f32 x = 0; x < width; x++)
	{
		for(f32 y = 0; y < height; y++)
		{
			u32 act = (u32)y * width + (u32)x;
			Block* current = &blocks[act];

			if(act1 + 3 >= 65536)
			{
				currentBuffer->append(vertices,act1-1,indexList,act2);
				mapMesh->addMeshBuffer(currentBuffer);
				currentBuffer->drop();
				currentBuffer = new scene::SMeshBuffer();
				act1 = act2 = 0;
				delete[] vertices;
				delete[] indexList;
				vertices = new S3DVertex[65536+1];
				indexList = new u16[65536*2+1];
			}
			SColor color = SColor(255,
				(current->type == 0 || current->type == 3 ? 0 : 255),
				(current->type == 0 || current->type == 3 ? 255 : 0),
				0);
			vector3df buffer = vector3df(x-1,y-1,current->uppleft);
			buffer *= multiplier; // Just to scale the vertice
			vertices[act1].Pos = buffer;
			vertices[act1].Normal = buffer.normalize();
			vertices[act1].Color = color;

			buffer = vector3df(x-1,y+1,current->uppright);
			buffer *= multiplier;
			vertices[act1+1].Pos = buffer;
			vertices[act1+1].Normal = buffer.normalize();
			vertices[act1+1].Color = color;

			buffer = vector3df(x+1,y+1,current->lowright);
			buffer *= multiplier;
			vertices[act1+2].Pos = buffer;
			vertices[act1+2].Normal = buffer.normalize();
			vertices[act1+2].Color = color;

			buffer = vector3df(x-1,y+1,current->lowleft);
			buffer *= multiplier;
			vertices[act1+3].Pos = buffer;
			vertices[act1+3].Normal = buffer.normalize();
			vertices[act1+3].Color = color;

			indexList[++act2]	= act1;
			indexList[++act2] = act1+1;
			indexList[++act2] = act1+2;
			indexList[++act2] = act1+3;
			indexList[++act2] = act1+1;
			indexList[++act2] = act1+2;

			act1 += 4;
		}
	}
	currentBuffer->append(vertices,act1-1,indexList,act2);
	mapMesh->addMeshBuffer(currentBuffer);
Can you understand it?

To help, there's the Block class:

Code: Select all

class Block {
public:
	f32 uppleft,
		uppright,
		lowleft,
		lowright;
	u8 type;
};
It just holds the height of the block. The position I have to figure it out. But it works with normal mesh nodes!

(If you're thinking I'm crazy to do a poorly file struct like that which just holds the height of the map, those map files aren't mine. They're from Gravity's ragnarok. The .gat files.)
Gtoknu
Posts: 9
Joined: Sat Sep 11, 2010 12:51 am

Post by Gtoknu »

I found the error. Now My game get 40FPS (It was 10FPS) :D

For anyone with the same error: When making the MeshBuffer, Set the Vertices and Index Arrays Limit, clean the IMesh MeshBuffers array, and etc. Or Your program will crash :D
Post Reply