Should device->drop() handle all deallocation?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Guest

Should device->drop() handle all deallocation?

Post by Guest »

Hi

When I call GameMain::GetInstance()->GetIrrDevice()->drop();

as the last line of code in my program it crashes. Shouldn't irrlicht handle to deallocate everything? As it is right now I have no idea if I am doing something wrong or if it's an irrlicht bug.

Thanks

Joachim
Unwise owl
Posts: 6
Joined: Thu May 20, 2004 9:40 pm

Post by Unwise owl »

EDIT: Disconsider what I've written if you have succeeded in actually calling the device pointer elsewhere after its creation.

I had a similar problem last night; are you sure your device pointer is valid? If you've only initialized the device so far in your code the chances are it isn't. It turned out mine wasn't. Whenever I attempted to modify it (createDevice()), the result was not stored at the correct address, even though the right effects happened (the window got shows up). Any attempts to call a member function by this pointer though was futile and would only result in crashes because apparently I had made a local copy in main() of the actual pointer I intended to modify...
Razed
Posts: 9
Joined: Mon May 10, 2004 9:43 am

Post by Razed »

That is the correct procedure, so the most likely problem is the pointer is invalid somehow. Two of the most likely causes:

1.) The createDevice() may fail in which case the pointer will be null. If drop() is then called it will crash.

2.) If drop() is being called twice you'll get a double delete, which will then crash.
Luke923
Posts: 59
Joined: Wed Nov 05, 2003 5:26 am

Post by Luke923 »

The best way to handle this, since you will want to assure that all memory assigned gets deallocated. What I tend to do is in mu shutdown code is call the following:

Code: Select all

if(IDevice)     IDevice->drop();
This way, I can make sure that if the IrrlichtDevice exists, it gets deleted. Otherwise, I don't worry.
"Object-oriented programming is an exceptionally bad idea which could only have originated in California."
- E.W. Dijkstra
Post Reply