#93371 - delfare - Tue Jul 18, 2006 8:52 pm
hi,
I have a problem with malloc : malloc return used memory(not NULL) and when I use the data, my game bug.
how can I solve this problem?
example :
in my game, I have :
Code: |
u16 *map1, *map2;
map1 = (u16*)malloc(sizeof(u16)*256*192);
map2 = (u16*)malloc(sizeof(u16)*256*192);
int i;
for(i=0;i<256*192;i++)
{
map1[i]=PA_RGB(31,31,31);
map2[i]=PA_RGB(31,31,31);
}
|
and it bug.
if I delete this, it work fine.
_________________
If I speak badly, it's because I speak french and I am 15
PA 3d tutorial : http://delfare.pizz.biz
#93496 - entilzha - Wed Jul 19, 2006 3:50 pm
Hmm, I read somewhere else on the forum that malloc is broken in the latest release (r19) of devkitARM. The options given by Tepples were to downgrade to r18, or wait for r20. :)
http://forum.gbadev.org/viewtopic.php?t=10434
#93500 - wintermute - Wed Jul 19, 2006 4:03 pm
Please check your facts before posting misinformation.
There is a problem with malloc on gba it works fine on other platforms.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#93533 - delfare - Wed Jul 19, 2006 7:25 pm
yes but what can I do?
is there another memory allocator?
PS : I use devkitpro updater 1.3.1
_________________
If I speak badly, it's because I speak french and I am 15
PA 3d tutorial : http://delfare.pizz.biz
#93558 - wintermute - Wed Jul 19, 2006 9:56 pm
insufficient information for a meaningful answer.
Why are you allocating memory to use as a screen?
What does PA_RGB do?
What does "it bug" mean?
What are you doing with map1 and map2 later?
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#93564 - sajiimori - Wed Jul 19, 2006 10:30 pm
As entilzha mentioned, you can downgrade to r18.
You could also write your own allocator, but if you have to ask how, that's probably not the best option. :)
#93566 - PeterM - Wed Jul 19, 2006 10:33 pm
I think what Wintermute was getting at was that there's nothing wrong with malloc for DS, so the bug must be elsewhere.
_________________
http://aaiiee.wordpress.com/
#93576 - tepples - Wed Jul 19, 2006 11:25 pm
entilzha wrote: |
Hmm, I read somewhere else on the forum that malloc is broken in the latest release (r19) of devkitARM. |
Did you read this in the GBA section? The GBA startup code and the Nintendo DS startup code, which set up the heap, have separate bugs.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#93736 - wintermute - Thu Jul 20, 2006 10:52 pm
delfare wrote: |
Quote: |
What does "it bug" mean?
|
the game stop
|
I don't really see anything with that code that might cause the DS to freeze, if that's what you mean. Is there any chance that you're running close to memory limits and the ~200k allocated for your double buffer is pushing it close to the edge?
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#93814 - entilzha - Fri Jul 21, 2006 12:36 pm
wow, I'm totally sorry man.. Didn't mean to post misinformation. I didn't know the DS was free of this problem.
#93923 - HyperHacker - Sat Jul 22, 2006 12:21 am
So if I understand this correctly, when you call malloc() it returns a pointer to memory that's already in use? I had this problem in a Windows program just a few days ago. The problem was that I was moving buffers around using realloc() but still using the old pointers and thus writing into random areas of memory. Memory corruption bugs like this can be tricky bastards because the faulty code often doesn't fail, but causes some other function to misbehave somehow.
_________________
I'm a PSP hacker now, but I still <3 DS.
#93957 - tepples - Sat Jul 22, 2006 2:30 am
Which is part of why there's a push toward "safe" languages such as Java, Objective CAML, C#, C++/CLI, etc.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.