Deleting the 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
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Deleting the Device

Post by Bersi »

Hi I got a problem with irrlicht 1.4. When the program is closing I call IrrlichtDevice::drop(). With the debugger I can see that ReferenceCounter is 1 so I never called drop before. ReferenceCounter is then decremented to 0 and so the following code is triggered:

Code: Select all

if (!ReferenceCounter)
{
	delete this;
	return true;
}
The problem is the line with the delete in it. When I run this line with the debugger I got the following error (MS Visual Studio 2008):
Windows has triggered a breakpoint in MyProgram.exe.

This may be due to a corruption of the heap, which indicates a bug in MyProgram.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while MyProgram.exe has focus.

The output window may have more diagnostic information.

The output window has this content:
First-chance exception at 0x7c97d801 in MyProgram.exe: 0xC0000005: Access violation reading location 0x014a9070.
HEAP[MyProgram.exe]: Invalid Address specified to RtlFreeHeap( 00A00000, 02470040 )
Windows has triggered a breakpoint in MyProgram.exe.

This may be due to a corruption of the heap, which indicates a bug in MyProgram.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while MyProgram.exe has focus.

The output window may have more diagnostic information.
The program '[2112] MyProgram.exe: Native' has exited with code 0 (0x0).

Can someone help? I don't know why the deletion fails.

The this-Pointer of IrrlichtDevice is valid before the deletion but something seems to be broken.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

And the stack trace is...?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The actual code might also help. There are infinite reasons which could trigger this error. Though some or more likely - like you are calling that for an invalid pointer for example. But you need to give more information or we have no way to help you.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

Hmm there are about 10000 lines of code (without the irrlicht engine). It's difficult to show you all of that. I know that you can't locate the bad code but perhaps you have an idea how I can cause this error. For example by calling a drop-function of a metatriangleselector-object or something like that.

Don't know how to view the stack trace.



The most stuff is done by self-written manager-classes. I use irrlicht only for drawing (don't use file-classes, loaders or something like that) and for the gui environment.

So the only things I do with the device is add and remove things to the attached gui environment, add and remove things to the scene manager and draw things with the video driver.

If you have a guess where the error can be I will post some code, but it's too much for posting all of it.


Thanks for help
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

I have an idea. I have a class for every possible screen, like ingame-screen, main menu, intro, outro and so on. Every class derives from irr::IEventReceiver. When a screen should be initialized it sets the event receiver of irrlicht to the own this-pointer. All these screen-classes are singletons that destroy themselves at the end of the program. Could this be the problem?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

It probably is something like that where you're deleting something that the device is using before deleting the device and so the device then tried to use/delete that thing you've deleted and then crashes as a result... You could try preventing the screen-classes from deleting themselves and see if that fixes it.
Image Image Image
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

Ok I found the problem. My menu-manager-classes use a skin that is created by the createSkin function. It's a static IGUISkin-pointer. When the program should close this skin should be dropped, so I call drop() for it. But this seems to be the problem. But I don't know why. Thought that drop() is ok for things that was returned by a 'create'-function.


Edit: I checked the drop-function for the skin. ReferenceCounter is 2 and is decremented to 1, so it won't delete the skin-data. So I don't understand why there is an error.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Calling drop is probably fine if you created it with a create function. Maybe you drop it after you already destroyed the device?
But it's really close to impossible to help you without additional information. Maybe you can reduce the code to a testcase that still does reproduce the bug? Or at least post the lines where you define and declare your devicepointer and also those where you create/destroy it.

Your debugger should already give you a callstack when you compile with debug information. Learn to use the debugger. It is rather trivial to use and you will need it anyway regularly as programmer.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

At least I found the problem. There is a small info box that also uses the skin and also drop it after calling it's destructor. So the skin is dropped twice.

Thanks for your help.


@CuteAlien: Yes I know the callstack but it wasn't very useful for me till now. I work with the debugger and use breakpoints and step-by-step-debugging. For most cases this worked fine for me. But thanks for the information.
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

Hmm I noticed that there were two different skins. One for the small info box and one for all other menus. So this should work (the two drops). But I added a feature in the irrlicht engine to use other skins for every gui window, called override skin. I think I've made a mistake there. Have to look at for a while...
Post Reply