Glibc pointer error upon deletion of irr:device

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
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Glibc pointer error upon deletion of irr:device

Post by AzP »

Hi

Me and my project group at a course in Game Design have created a game influenced by bzFlag. It's basically "done", even though we'd like to fix a lot of stuff in it as it is today. The game is a multiplayer game, with a dedicated server, and is actually playable, as is.

However, we chose Irrlicht as our scene-graph manager (/game engine) and it's been working great. The game was developed on Windows 2000, but I'm a linux guy myself, so of course I ported it (which wasn't a problem since the network and sound code was written in SDL (cross platform) and all graphics in Irrlicht) to Linux as fast as I could.

Now to the problem. I've searched the forum, and haven't found any answers to this question.

I get some kind of pointer error when I delete the pointer to the device.
The warning is:
error wrote:*** glibc detected *** corrupted double-linked list: 0x0828ca20 ***
glibc stops the program when it receives the warning, but after some debugging I managed to narrow the crash down to these line of code. The crashing codes are inside the === chars:
(I'm sorry for the large print out, but I thought I'd give the whole picture up to the crash.)

Code: Select all

int main(int argc, char* argv[])
{
    MyEventReceiver receiver; 

// Create device
    device = createDevice (video::EDT_OPENGL, core::dimension2d<s32>(windowX, windowY), 32, false, false, true, &receiver); 
	device->setResizeAble(false); 
	 
	// Check if device could be created. If not, terminate.
	if (device == 0) 
    {
        return 1; 
    }

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
	
	
	/*************** 
    - Create Menu - 
    The menu will be visible when the game starts.
    Here the user will be able to read instructions and 
    start a new game
    ***************/

    IGUIEnvironment* env = device->getGUIEnvironment();
	IGUISkin* skin = env->getSkin();
	.
	:
	.

	/*********
    Add background image.
	*********/
	IGUIImage* img = env->addImage(
	driver->getTexture("../media/menu/menubg.jpg"),
	position2d<int>(0,0));	
	
 	/*********
	Add a fader for fading in from a color to the menu. The fader HAS to be created before adding the buttons.
	*********/
    IGUIInOutFader* fader = env->addInOutFader();
    fader->setColor(video::SColor(0,2,2,2));
    fader->fadeIn(2000);
	
	.
	:
	.

	/****************************
	Create the variables to check for timeout upon connection
	****************************/
	.
	:
	.

    /******
    Menu is finished, start with the rest of the program, 
    drop the old stuff and create a new device
    *******/
    
	fader->drop();
	img->drop();
	env->drop();

====================================
	device->drop();
	device = createDevice (video::EDT_OPENGL, core::dimension2d<s32>(windowX, windowY), 32, false, false, true, &receiver); 
====================================

	/*************
	Create the camera
	*************/
	scene::ICameraSceneNode *camera = device->getSceneManager()->addCameraSceneNode();
	camera->setFOV(PI/2.0f);
	scene::ISceneNode *cameraLookAtNode = smgr->addEmptySceneNode(); //node the camera is set to look at
I don't understand why this would create any pointer errors. I tried removing the device->drop() but then it crashed at the next lines instead, when creating the cameras. What to do, what to do?
A guy in out group tried it on WinXP, and it crashed for him.. When another friend tried it in XP it worked.

I'm very confused and don't really know what to do.. gdb just outputs this backtrace:

Code: Select all

#0  0xffffe410 in __kernel_vsyscall ()
#1  0xb7abc3b1 in raise () from /lib/tls/libc.so.6
#2  0xb7abddcd in abort () from /lib/tls/libc.so.6
#3  0xb7aef777 in __fsetlocking () from /lib/tls/libc.so.6
#4  0xb7af5597 in malloc_usable_size () from /lib/tls/libc.so.6
#5  0xb7af570b in malloc_usable_size () from /lib/tls/libc.so.6
#6  0xb7af5c5f in malloc_usable_size () from /lib/tls/libc.so.6
#7  0xb7af5f59 in free () from /lib/tls/libc.so.6
#8  0xb7f19a3a in _nv000039gl () from //usr//lib/opengl/nvidia/lib/libGL.so.1
#9  0x08274e50 in ?? ()
#10 0xb7455926 in _nv000064gl () from //usr//lib/opengl/nvidia/lib/libGLcore.so.1
#11 0x00000000 in ?? ()
Please help us, I appreciate anything.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I think you should check if the device exists before droping:

Code: Select all

if(device) device->drop();
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Post by AzP »

I totally cleaned out all code related to the starting menu. This actually made the game start! =)

Now I have to add each line again to see where it's going wrong. It seems to crash at the env-drop() too.. And if I just skip that part, it crashes later when it gets an event from the keyboard (probably because the menu is still somewhere in the background)...

I'll try with your proposal, thank you
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Hmmm, another question: why do you drop them both ???
I think device and env shouldn't be droped !!!
At least device !!!
I don't know the reason you drop them and create the device again by using the same params as the first time ???
Maybe there are still some objects you want to delete, but then you shoud better remove all objects and not drop and recreate the device !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Post by AzP »

I agree with you. I have no idea why they chose to drop the device and then recreate it. It is very redundant.

I will remove the dropping of the device etc. But the env, the fader and the img I believe should be dropped, since we don't need them any more.

Like I said before, if I start the game without dropping the env, it behaves very strangely. It fires bullets all the time, and then crashes.

Now I'm ready for sleep, but I'll get cracking at this tomorrow. If I get it working, I'll put up a link for you to download so you can try it =)

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

Post by vitek »

They are probably displaying a menu screen that allows the user to select options like the window size and stuff. If they do this, then they need to recreate the device...

Your best bet is to start with the following line...

Code: Select all

   env->drop(); 
Unless you have grabbed the gui environment, you are effectively deleting the environment. Then, just a few lines later, you drop the device. The device drops the environment as part of its destruction process. When you delete the same pointer twice, you get crashes.

If your game has problems because you don't delete the environment, then you should isolate and solve those problems.

Travis
Post Reply