mysterious segfaults

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
binford
Posts: 28
Joined: Tue Nov 14, 2006 10:32 am
Location: Munich

mysterious segfaults

Post by binford »

Hi there,

I just started using irrlicht, and everything worked like a charm in the beginning. But now I'm getting segfault all over the place. I shrinked my app to a few lines of code, and it still fails:

Code: Select all

int main(int argc, char *argv[])
{
	IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>( 640, 480 ), 16, false, false, true, 0 );
	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	// add camera
	CameraController* cameraController =
		new CameraController( smgr, vector3df(1900*2,900*2,3700*2), vector3df(1900*2,300*2,3400*2), 1 );

	// create event receivers
	GlobalEventReceiver globalEvents( device );
	globalEvents.addEventReceiver( cameraController );
	device->setEventReceiver( &globalEvents );

	int lastFPS = -1;

	while( device->run() )
	{
		driver->beginScene(true, true, SColor(0,200,200,200));

        [color=red]smgr->drawAll();[/color]
		guienv->drawAll();

		cameraController->updateCamera();

		driver->endScene();


		// display frames per second in window title
		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			core::stringw str
			   = L"Terrain Renderer - Irrlicht Engine [";
			str += driver->getName();
			str += "] FPS:";
			str += fps;
			guienv->addStaticText( str.c_str(), rect<s32>( 500, 10, 200, 175 ), true, true, 0, -1, true );
			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
	}
	device->drop();
}
So even when there is nothing in the scene graph, there should be no segfault?! Am I right?

The segfault occurs at CSceneManager::drawAll(). I'm (yet) not intelligent enough to track it down to the exact line of code.

Any ideas?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

What's your CameraController class like? I wonder if that's where the problem is as everything else looks normal.
Image Image Image
Archive
Posts: 6
Joined: Tue Nov 14, 2006 8:08 am

Post by Archive »

hmmm, try moving your :

"cameraController->updateCamera(); "

outside of the beginscene/endscene area.

Also it doesn't look like your camera got registered with the smgr?

I'd do 2 things, remove your eventreceiver classes, to make sure the problems not there, and post your cameraController class, so that we can take a look at that.
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

Post by Lideln »

Hi,

Always use DBC (Design By Contract, google if u never heard about it) when you code, or at least use assert !
Maybe the error comes from the engine... But maybe not !
So, each time you use a pointer, check it first with assert.

Also, always initialize your variables, etc etc (for example pointers that are not initialized are NOT NULL)

I hope this method will help you find what's failing

Have a nice day,


EDIT : what said Archive is right : always update your camera before drawing the scene (it may not be the cause of the segfault, but it's far better this way, as a general rule)
--
Lideln, France
binford
Posts: 28
Joined: Tue Nov 14, 2006 10:32 am
Location: Munich

Post by binford »

Ok, guys, I just started to write sth like "But no, my beloved CameraController IS PERFECT (because I did it)" and pasted the code in this form just to recognize this silly piece of code

Code: Select all

for( int i = 0; i < KEY_KEY_CODES_COUNT; i++ ) {
		m_states[i] = false;
	}
and in the header

Code: Select all

bool m_states[4] ;
I apologies for this post. Thanks anyhow.
Post Reply