What is difference between closeDevice() and drop() ?

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
keynet
Posts: 18
Joined: Wed Jun 27, 2012 9:07 am

What is difference between closeDevice() and drop() ?

Post by keynet »

Hi. I have a simple(but maybe complex) question about IrrDevice.

As the topic subject, what is the difference between IrrDevice->closeDevice() and IrrDevice->drop() ?

In my project, I used closeDevice() when certain button(ex.QUIT or EXIT button) GUI Event occurs,

and used drop() after while(IrrDevice->run()) {} .

But some strange phenomenon happens when I changed closeDevice() to drop(), because I think it is more proper to use drop().

I only know that I should use drop() function when the device should be deleted (I.E., memory about device should be gone),
but things are not so easy as I think.

What is accurate difference between them?
From Seoul, South Korea
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: What is difference between closeDevice() and drop() ?

Post by greenya »

When you use closeDevice(), you inform Irrlicht that you want him next time you call device->run() to return "false", so your rendering loop will finish and you can correctly drop the device (and other resources). If you will call drop() on the device, next call to device->run() will crash your app (well, any call to "device->..." will crash).
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: What is difference between closeDevice() and drop() ?

Post by hybrid »

Yes, the idea is to always just call closeDevice in your app, and only do the drop at a single place after you left the render loop the last time. You should even call run() at least one more time, to handle the window close events properly.
keynet
Posts: 18
Joined: Wed Jun 27, 2012 9:07 am

Re: What is difference between closeDevice() and drop() ?

Post by keynet »

Oh I see.. I got it briefly.

Then what function do I have to use to wake up the closed device (the IrrDevice that called device->closeDevice()) ?
I mean, after I call closeDevice(), how can I make device->run() returns true to render the device?
Or should I just create a new device even I only closed device, not drop ?

Thank you for your answers, and thank you in advance!
From Seoul, South Korea
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: What is difference between closeDevice() and drop() ?

Post by hybrid »

No, a closed device is dead, it just still occupies some memory. But usually even the window will disappear upon closeDevice already - only Windows has some problems here which is why you have to call run() once or twice after closeDevice. The drop will then mark the memory for disposal, usually removing everything immediately there. If you call drop earlier, this should also happen, but might fail due to internal references, or no proper clean up will leave some ressources, e.g. for d3d or the window handlers, left dangling in memory.
If you need the next device, create a new one after removing the old one. Better not two at once.
Post Reply