Seg Fault Problem

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
Coolkat88
Posts: 30
Joined: Tue Oct 03, 2006 3:14 pm

Seg Fault Problem

Post by Coolkat88 »

Hey guys,

Im having a little problem with a seg fault here.. and neither me, nor the debugger can seem to find it, just that it's there..

Now i just started a new Irrlicht project, and i put everything in like normal.. setup a class to read from the XML config file.. then create the device.. etc.. all worked fine.. i went ahead and added a class to manage my game states (like game init functions that do nothing at the moment, scene managers that manage nothing, etc.)

mostly it's just like a skeleton i will fill in later... regardless, everything works fine and when i CLOSE the window it hits a segfault.. so im thinking it might be with something not dying like it should be..

Code: Select all

             while(device->run())
             {
                                 
                   if(rpg->getInitState() == 1)
                        rpg->switchScene(0); // Main Menu

                   if(rpg->needChange() == 1)
                        rpg->switchScene(rpg->getSceneNum()); // Run Current Scene              
                                 
                                 
                   driver->beginScene(true, config.ZBUFFER, SColor(0,200,200,200));
                   
                   smgr->drawAll();
                   genv->drawAll();
                   
                   driver->endScene();
               
             }

             device->drop();
i don't see anything really in here that would effect the way irrlicht closes.. or what not..

however, i did go ahead and add in for realtime restarts if needed (or whatever you call it when you want the user to edit the configuration from a panel IN GAME and then the game restarts itself basically with the new settings)

and this is all done with a do while loop.

Code: Select all


// include headers

int main()
{

// init the classes
IrrlichtDevice *device = 0;
EventHand *handle = new EventHand;
RPGDevice *rpg;
// etc.


do
{

// parse the XML using a function that uses the IXML features, ive  used this exact class in a previous project and it worked there with no problems.

//create the device using the configurations, the window DOES create when the project runs so this most likely works correct as it changes correctly according to the config.xml file

device->setEventReciever(handle);
handle->setDevice(device);
rpg->beginDevice(device);

while(device->run())
{
    // check what is posted above for this loop
}

device->drop();

restart = rpg->getRestart();

} while(restart == 1);

delete handle;

return 0;

}
that is more or less the framework of that.. and for the moment, where i move the device around it's basically

Code: Select all

beginDevice(...)
{
    device = dev;
    scenenum = 0;
    // more variables with values reset to whatever i need them to be.
}
and EventHand is inheriting IEventReceiver.. everything compiles fine, no warnings, errors, or anything.

if you guys need more i can post it.. since im not that far in i could just rewrite it again and compile more often to find the seg fault but id rather not if you all can see something.

Thank you in advance,
-Coolkat
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Hmm, in the 2nd code snipet you drop the device before while(restart == 1);
then the loop goes up and works again with device, that you droped just before !!!

Also it can be that you try to clear some Irrlicht things inside the destructor of the rpg class !?!?!
But if you close the prog the device is droped before the class is terminated, that means the destructor tries to work with an not initialised device (same as before) !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Coolkat88
Posts: 30
Joined: Tue Oct 03, 2006 3:14 pm

Post by Coolkat88 »

Acki wrote:Hmm, in the 2nd code snipet you drop the device before while(restart == 1);
then the loop goes up and works again with device, that you droped just before !!!

Also it can be that you try to clear some Irrlicht things inside the destructor of the rpg class !?!?!
But if you close the prog the device is droped before the class is terminated, that means the destructor tries to work with an not initialised device (same as before) !!!
well it doesn't actually Acki.. see right before device->drop() is another while loop which is where device->run(), so it shouldn't hit the drop() function until after the game closses, which is when it SHOULD encounter it.. but i did go ahead and try and put it after that (right before the delete handle; which is where i assumed you meant for it to go) and it still seg faulted.

the destructor of the RPG class doesn't touch irrlicht realted stuff at the moment.. i THOUGHT about maybe it needed to drop too but i tried that and it said there was a problem with ReferenceCounter in IUnknown.h so i figured that wasn't going to work right so i just took that out. however, would taking device->drop() out of int main and sticking it in the destructor for the RPG class work better you think?
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

Curious, what does your getRestart() function look like?
system-independent, adj.:
Works equally poorly on all systems.
-- unknown
Coolkat88
Posts: 30
Joined: Tue Oct 03, 2006 3:14 pm

Post by Coolkat88 »

Code: Select all


void getRestart() const;

....


void RPGDevice::getRestart() const
{
      return restart;
}

it is just checks to see if i need to restart the device.. there is a function that sets the restart if need be that just sets the restart = 1; and then closes the device but this isn't even used yet or tested..
Coolkat88
Posts: 30
Joined: Tue Oct 03, 2006 3:14 pm

Post by Coolkat88 »

ugh...

ok i solved the issue.. it was with

RPGDevice *rpg = new RPGDevice;
Post Reply