![]() |
|
Unloading datafile causes program to crash. |
XcronZ3X
Member #8,222
January 2007
|
Ok so here's basically the code: allegro_message("Sounds destroyed!"); //debug The sounds destroyed message comes up and then BOOM! The program crashes! This is pretty strange and I cannot seem to think of what the reason may be. Before the destruction of the sounds, I also free up and destroy bitmaps. All the bitmaps and sounds, etc., come from the datafile and I was thinking that that may possibly be the problem but I see no reason for that to be so...does the call to unload_datafile() do something I'm not aware of other than freeing up all the objects in the datafile and removing it from memory?? |
Matthew Leverton
Supreme Loser
January 1999
![]() |
You're freeing the stuff twice. unload_datafile will unload all the objects. Don't manually unload the individual elements beforehand. |
XcronZ3X
Member #8,222
January 2007
|
Mmmm, so it was as I thought...but it feels strange that unload_datafile would even take care of all of the memory that I used when taking objects from the datafile and putting them into objects that I create while the program is running.. It also feels weird that by freeing the objects I create while the program is running go all the way to the root objects from the datafile and free them up as well.. |
Matthew Leverton
Supreme Loser
January 1999
![]() |
This is broken: DATA *dat = load_datafile("foo.dat"); BITMAP *bmp = dat[foo].dat; destroy_bitmap(bmp); unload_datafile(dat); But if you are blitting the object to another bitmap you create, then you must unload both. It's simple to remember. If you use create/load_bitmap, then you need to destroy it. |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
Remember, XcronZ3X - A pointer (BITMAP *bmp) just "points" to a chunk of data, in this case a bitmap. When you do BITMAP *bmp = dat[foo].dat; you copy the pointer to the bitmap data - not the actual bitmap data.
|
Tobias Dammers
Member #2,604
August 2002
![]() |
In other words, treat each datafile in only one of the following ways. Whatever you do, don't mix the above unless you know exactly what you're doing. --- |
|