smgr->drawAll() crash

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
markanderson
Posts: 30
Joined: Thu Mar 16, 2006 6:21 pm

smgr->drawAll() crash

Post by markanderson »

Hello All -

Just a quick question - randomly I get a crash on the smgr->drawAll() line. I presume this means I've messed up somewhere but can't work out how to trace it back to the source. Does anyone have any suggestions?

Also (while I'm here ;) I occassionally get a message in the console window saying 'Can not draw triangles, too many primitives'. My app rarely draws more than 5 cube nodes and maybe 10 billboards. Is that really enough to cause problems?

Thanks,

Mark.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: smgr->drawAll() crash

Post by greenya »

markanderson wrote: Just a quick question - randomly I get a crash on the smgr->drawAll() line. I presume this means I've messed up somewhere but can't work out how to trace it back to the source. Does anyone have any suggestions?
No.
Because all people that able to read minds are have a vocation. So demonstration of the source code is highly recommended.
That's why I have no suggestions.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

presume this means I've messed up somewhere but can't work out how to trace it back to the source. Does anyone have any suggestions?
The best thing we could do for you would be to tell you to step into the source with the debugger. Most likely you are dropping something that you shouldn't be or you are removing something from a list while iterating over it.

Someone might be able to help you if you posted a stack, but you need to use the debugger to get that.
I occassionally get a message in the console window saying 'Can not draw triangles, too many primitives'
This happens when you have a mesh that has to many triangles. Most likely you have a really big mesh or terrain. If you are using a terrain scene node, you should use a 129x129 heightmap image. Anything bigger than 256 might fail with this message.

Travis
markanderson
Posts: 30
Joined: Thu Mar 16, 2006 6:21 pm

Thanks

Post by markanderson »

My height map was 256x256 so I've reduced it. The terrain did sometimes flash on and off when the 'too many primitives' message was flashing now that I think of it.

Regarding the crash on smgr->drawAll() I did step through the debugger - and that's the line where it crashed. The call stack didn't help nor did the locales. I accept it's most likely my fault and was just trying to find out if it was indicative of any typical noob mistakes.

I'll go through me ->drop() statements as Travis suggested and see I can find. Thanks again,

Mark.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If the app fails at that verx line you either have a corrupted scene manager (quite unlikely, though, that it only happens occasionally) or it happens inside the method. Then you'd have to step inside the method to see where it crashes. So set a breakpoint at that statement and start single stepping.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Just FYI, to be able to step inside the dll, I believe you'd need to rebuild it with debug information enabled.

Travis
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

Vitek, even if i do that i can't step into the dll with c::b. Any tips or something i must do to step between projects?

What version of irrlicht are you using? Any custom scene nodes?
If you don't have anything nice to say, don't say anything at all.
markanderson
Posts: 30
Joined: Thu Mar 16, 2006 6:21 pm

Post by markanderson »

I will try rebuilding the dll in debug mode and stepping through it. That didn't occur to me, thanks vitek.

I'm using the a SVN build (618 I think) and do have a customscenenode Luben. I've pasted the class below, it's from the tutorials and only slightly modified. I've removed the comments for brevity.

Code: Select all

class CSampleSceneNode : public scene::ISceneNode
{
	core::aabbox3d<f32> Box;
	video::S3DVertex Vertices[4];
	video::SMaterial Material;


public:

	CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, core::vector3df pos_start, core::vector3df pos_end)
		: scene::ISceneNode(parent, mgr, id)
	{
		Material.Wireframe = false;
		Material.Lighting = false;

			Vertices[0] = video::S3DVertex(pos_end.X,pos_end.Y,pos_end.Z, 1,0,0, video::SColor(255,255,255,255), 1, 1);
		Vertices[1] = video::S3DVertex(pos_start.X,pos_start.Y+20,pos_start.Z, 0,1,1, video::SColor(255,255,255,255), 1, 0);
		Vertices[2] = video::S3DVertex(pos_start.X+20,pos_start.Y-20,pos_start.Z+20, 0,0,1, video::SColor(255,255,255,255), 0, 0);
		Vertices[3] = video::S3DVertex(pos_start.X-20,pos_start.Y-20,pos_start.Z-20, 1,1,0, video::SColor(255,255,255,255), 0, 1);
		
		Box.reset(Vertices[0].Pos);
		for (s32 i=1; i<4; ++i)
			Box.addInternalPoint(Vertices[i].Pos);
	}


	virtual void OnRegisterSceneNode()
	{
		if (IsVisible)
			SceneManager->registerNodeForRendering(this);

		ISceneNode::OnRegisterSceneNode();
	}

	virtual void render()
	{
		u16 indices[] = {	0,2,3, 2,1,3, 1,0,3, 2,0,1	};
		video::IVideoDriver* driver = SceneManager->getVideoDriver();

		driver->setMaterial(Material);
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4);
	}

	virtual const core::aabbox3d<f32>& getBoundingBox() const
	{
		return Box;
	}

	virtual u32 getMaterialCount()
	{
		return 1;
	}

	virtual video::SMaterial& getMaterial(u32 i)
	{
		return Material;
	}	
};
I'm calling it like this:

Code: Select all

		CSampleSceneNode *beam = new CSampleSceneNode(device->getSceneManager()->getRootSceneNode(), device->getSceneManager(), 666, core::vector3df(nodelist[srcnodeid].posx, nodelist[srcnodeid].posy, nodelist[srcnodeid].posz), core::vector3df(nodelist[dstnodeid].posx, nodelist[dstnodeid].posy, nodelist[dstnodeid].posz));
		beam->setMaterialTexture(0, device->getVideoDriver()->getTexture("Media/laserbeam.bmp"));
		beam->setMaterialFlag(video::EMF_LIGHTING, false);
		beam->setID(sessionlist.size()-1+2000);
		sessionlist[sessionlist.size()-1].id = (sessionlist.size()-1)+2000;

		ISceneManager_assignTriangleSelectors(device->getSceneManager(), device->getFileSystem()); 
		scene::IMetaTriangleSelector* meta = device->getSceneManager()->createMetaTriangleSelector();
		ISceneManager_gatherTriangleSelectors(device->getSceneManager(), meta); 
		scene::ISceneNodeAnimator *anim = device->getSceneManager()->createCollisionResponseAnimator(meta, beam, core::vector3df(3,3,3), core::vector3df(0,0,0), core::vector3df(0,6,0));
		beam->addAnimator(anim);
		anim->drop(); 
I save the nodeid so that later I can beam->drop() later when I want to get rid of it.

Anything obviously wrong about the above?
markanderson
Posts: 30
Joined: Thu Mar 16, 2006 6:21 pm

Update

Post by markanderson »

I hope nobody minds me reigniting this thread but I have some more information which hopefully will lead to a fix.

I recompiled the Irrlicht DLL in debug mode so that I could walk the call stack when it crashes. The stack is as follows:
main()
CSceneManager::drawAll()
ISceneNode::OnAnimate()
CCameraFPSSceneNode::OnAnimate()
CSceneNodeAnimatorCollisionResponse::animateNode()
CSceneCollisionManager::getCollisionResultPosition()
CSceneCollisionManager::collideEllipsoidWithWorld()
CSceneCollisionManager::collideWithWorld()
CMetaTriangleSelector::getTriangles()
CTriangleSelector::getTriangles()
CTriangleBBSelector::getTriangles()
The specific line that causes the crash in CTriangleBBSelector::getTriangles() is:

Code: Select all

core::aabbox3d<f32> box = SceneNode->getBoundingBox();
Does anyone have any idea what is going on? The crashes seem to happen randomly, usually when the camera is moving (FPS camera) but not when its in contact with any nodes. Although I'm not sure if camera movement is the culprit. I'd really appreciate any help because this is the last big stumbling block for my app.

Thanks,

Mark.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

From the looks of it I'd guess that a scene node has been destroyed, but you haven't removed its triangle selector from the meta selector. This could happen if you removed a scene node from the scene graph, but didn't remove its selector. You can fix it in two ways. You can find the code that removes the node and add a line to remove the selector for that node just before you remove it...

Code: Select all

meta->removeTriangleSelector( node->getTriangleSelector() );
node->remove();
The other option is to clear the meta selector after every render and rebuild it after running any code that may remove scene nodes. I have already posted some sample code here that shows how to do that. The modified gather function has the benefit that it only includes selectors for scene nodes that are near the camera so it avoids searching through many triangles that are nowhere near the camera.
markanderson
Posts: 30
Joined: Thu Mar 16, 2006 6:21 pm

Thanks so much!

Post by markanderson »

Thanks vitek - that worked a treat. You're the man! ;]

I knew it would be something stupidly simple. I had no idea I had to remove a node's triangle selector from the meta selector. The irrlicht tutorials are great but they don't really give you a background in 3D development which would have helped. And I'm sure the other n00bs would benefit also.
Post Reply