gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > memory/stack/whatever corruption

#104610 - Bronto - Sat Sep 30, 2006 9:40 pm

I've been fighting this for some time now, but I just can't find the solution:

Since upgrading to devkit 19b, I'm having serious issues:
For example, I have allocated a char*, it points to 20d3f60. I pass it to another function, and suddenly it points to 2010d19. The difference is C3247(dec 799303). The pointer address may be different depending on when the code gets called, but the difference is always C3247. WTF?
I stripped the code down a lot for testing purposes, so I can be pretty much sure I'm not messing something up (ie write to memory areas where I shouldn't be writing to).
However the problem does not occur when I create a new project and include the functions, so perhaps it's a memory issue?
Anyone ran into similar issues? Perhaps the default stack size (or something like that) has changed in dk 19b?

#104613 - HyperHacker - Sat Sep 30, 2006 9:50 pm

I get weirdness like this a lot due to memory corruption, and usually it's difficult to see exactly what's causing it (eg treating an array of pointers to objects as an array of objects).
_________________
I'm a PSP hacker now, but I still <3 DS.

#104616 - Bronto - Sat Sep 30, 2006 9:59 pm

yeah, I had problems like that before, but I went over the code again and again, and I can't find anything wrong with my code. In fact, it happens before any complex operations are done, and I'm checking every pointer.
I'm also getting strange things like when changing a bool class member, another bool class member changes too

#104622 - Hermes - Sat Sep 30, 2006 10:14 pm

Well, i know a little bug from the interrupt dispatcher code:

When an interrupt handler is called , it turn to system mode and it use the application stack pointer.

Some times, the register sp is increased in the application and some local variables can be corrupted if an interruption calls to the handler in this moment and you use local variables here.

I had this problem when i developed to my Multithread library: it interrupt 1000 times per second and some times the application hang in strange form.

Then I move the sp register -128 bytes and call the function handler and when it return, i move the sp register +128 bytes and it work fine, hehehe. It indicates that interrupt handler is corrupting local variables of the application when it is called.

I remember a random fail too in my game 'Asteroids and Gems' using the LibDragon FAT library and LIBNDS (without my multithread library): some times when i save the options it hang.

In my Multithread library, i use an exclusive stack to call to the handlers and it don't hang yet

If you think it can be a problem of stack corruption in your application, it is very possible.

#104770 - sasq - Mon Oct 02, 2006 3:06 pm

You're saying libnds defaults to using the system stack? Might explain some strangeness I've seen too...