|
This thread is locked; no one can reply to it. |
1
2
|
Destroying bitmaps |
axilmar
Member #1,204
April 2001
|
Quote: I would stay away from non-pointer global objects that have destructors that free allegro objects. The order of destroying objects is not defined and when allegro itself closes before your allegro objects are freed you are screwed. With global pointers you should have no such problems. I solved the problem by installing an exit handler which is implicitely installed at first chance (after allegro is initialized). I think allegro should have a user-defined shutdown callback which is invoked at 'allegro_exit' in order to release any allegro resources at the right time...the exit point of an app can be other than main. |
Evert
Member #794
November 2000
|
Quote: Then why I can not destroy a bitmap after allegro exits? Because you cannot call Allegro functions when Allegro is not initialised (either before install_allegro() or after allegro_exit()). |
Felipe Maia
Member #6,190
September 2005
|
Quote: I think allegro should have a user-defined shutdown callback which is invoked at 'allegro_exit' in order to release any allegro resources at the right time...the exit point of an app can be other than main. Why? If you can just put a function before your program closes, that doesn't make sense at all. Besides, those aren't allegro resources, they're yours resources, you created them, not allegro. |
Paladin
Member #6,645
December 2005
|
Why would you want to explictly call set_gfx_mode(); to destroy the screen? Does it destroy every bitmap as well? |
axilmar
Member #1,204
April 2001
|
Quote: Why? If you can just put a function before your program closes, that doesn't make sense at all.
1. exit() might be called at various places. Quote: Besides, those aren't allegro resources, they're yours resources, you created them, not allegro. Of course. I meant resources managed with allegro i.e. bitmaps/sounds/etc. |
Felipe Maia
Member #6,190
September 2005
|
Quote: 1. exit() might be called at various places. If you call exit(), the memory will be freed anyway, there's no need for that. |
BAF
Member #2,981
December 2002
|
Quote: Can't you call the cleanup function before your program ends? Or can you not add with atexit a cleanup function? Instead of allegro_init, use install_allegro and pass null for atexit. Then add your atexit handler and at the end of that, call allegro_exit(). |
Kitty Cat
Member #2,815
October 2002
|
Quote: If you call exit(), the memory will be freed anyway Do not assume this. Even if the OS frees your process's memory (which it's not required to do) it may have system resources allocated, which aren't gauranteed to be freed when a process is closed, because other processes may be able to use it too. EDIT: Quote: Instead of allegro_init, use install_allegro and pass null for atexit. You can't do that. IIRC, you must pass a valid atexit handler. What's so bad about making sure you don't do Allegro cleanup code in a destructor called after allegro_exit? It's not hard. Register your own atexit handler after allegro_init that delete's what you new, and all is well. -- |
Evert
Member #794
November 2000
|
Quote: Even if the OS frees your process's memory (which it's not required to do) it may have system resources allocated, which aren't gauranteed to be freed A good example of this would be video bitmaps in Windows. I understand that this is better now, but it used to be so that these weren't released automatically. |
|
1
2
|