Memory corruption
Posted: Fri Aug 28, 2009 1:52 pm
Hello. First of all, sorry for my bad english, it's not my mother language:P. I am making a port of a game from PC to DS. This game works perfectly on PC with no crashes and at full speed but I am having some problems with ds, maybe due to DS limits.
This is the situation: the game loads fine, but after some time, it starts crashing. Most of the times after loading level 2.
There are 2 kind of crashes but I think they have the same origin. One is inside malloc. To be accurate, it's inside _malloc_r and game crashes completely. It is strange since if an error happens during the calling to malloc, it returns NULL pointer, instead, this makes the application to crash.
The other one seems by an unauthoriced access to the contento f a pointer. Just when I touch a coin in the game (it is destroyed and some spark object are created) the game freezes. I tried to search a bit the reason and it seems that when accessing a pointer when drawing, it crashes. the funny thing is that it is impossible that it has something uninitialized. I shall remember that the application works so fine on my computer.
Once I was able to stop and showing data before the application crashed. Data was corrupted, no number was right. I was lucky since I compared pointer to NULL to show that message, but it never catches it and the game crashes. I was very lucky because it seems that even pointers are corrupted and they point to somewhere else.
Also, before the chrash happens, everything else seems to work fine, and data is fine, AI is working, gfx are working, everything moves and plays well. Maybe pointers point to a forbidden address or unexistant and because of that it crashes randomply when I create something, or maybe creating something.
I do not use all the memory. Using a function that I found in uLib i read 2.2 Mb, so I should have enough space to work with. Is it possible that it have the pointers spread arround everywhere and then it doesn't find free memory and returns any pointer?
I am about changing all the dynamic lists to static arrays so I reduce the number of mallocs.
Any idea? :s thanks in advance
This is the situation: the game loads fine, but after some time, it starts crashing. Most of the times after loading level 2.
There are 2 kind of crashes but I think they have the same origin. One is inside malloc. To be accurate, it's inside _malloc_r and game crashes completely. It is strange since if an error happens during the calling to malloc, it returns NULL pointer, instead, this makes the application to crash.
The other one seems by an unauthoriced access to the contento f a pointer. Just when I touch a coin in the game (it is destroyed and some spark object are created) the game freezes. I tried to search a bit the reason and it seems that when accessing a pointer when drawing, it crashes. the funny thing is that it is impossible that it has something uninitialized. I shall remember that the application works so fine on my computer.
Once I was able to stop and showing data before the application crashed. Data was corrupted, no number was right. I was lucky since I compared pointer to NULL to show that message, but it never catches it and the game crashes. I was very lucky because it seems that even pointers are corrupted and they point to somewhere else.
Also, before the chrash happens, everything else seems to work fine, and data is fine, AI is working, gfx are working, everything moves and plays well. Maybe pointers point to a forbidden address or unexistant and because of that it crashes randomply when I create something, or maybe creating something.
I do not use all the memory. Using a function that I found in uLib i read 2.2 Mb, so I should have enough space to work with. Is it possible that it have the pointers spread arround everywhere and then it doesn't find free memory and returns any pointer?
I am about changing all the dynamic lists to static arrays so I reduce the number of mallocs.
Any idea? :s thanks in advance