Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

I have this for loop that calls GETRAND. For some weird reason, my app crashes with a message "Stack overlow GETRAND" on the 720T emulator. Any ideas why?

Thanks.

Can you post some code. What is the loop doing and where is it in your app? Are you using recursion?

Can you post some code. What is the loop doing and where is it in your app? Are you using recursion?

I think there is a stack overflow when you use GETRAND - especially when you are asking it to generate a lot of random numbers in a loop.
Try creating a loop that generates random numbers
uint8 rand;
for(i=0;i<128;i++){
for(j=0;j<128;j++){
GETRAND(&rand)
}

Then put it on the phone and activate the debug code ###1 which checks the heaps integrity - you may find it will crash somewhere around i = 39.
I've been having problems with it all afternoon and have found that my code is fine if i dont use GETRAND - except i do need random numbers so i have to somehow get round this.
I'm using BREW 2.1 with the lg8000 and the ARM compiler
Any ideas?

I think there is a stack overflow when you use GETRAND - especially when you are asking it to generate a lot of random numbers in a loop.
Try creating a loop that generates random numbers
uint8 rand;
for(i=0;i<128;i++){
for(j=0;j<128;j++){
GETRAND(&rand)
}

Then put it on the phone and activate the debug code ###1 which checks the heaps integrity - you may find it will crash somewhere around i = 39.
I've been having problems with it all afternoon and have found that my code is fine if i dont use GETRAND - except i do need random numbers so i have to somehow get round this.
I'm using BREW 2.1 with the lg8000 and the ARM compiler
Any ideas?

The documentation for GETRAND specifically suggests against calling it that way:
Quote:The sequence is seeded by the current time, so multiple calls may give identical results unless separated by at least several milliseconds. For best results, call it once per invocation of event handler function.
So if you need that many random numbers, fill an array with GETRAND instead of a single value.
It's really strange that it would cause a stack overflow though. The stack has to be exactly where it was when you called it or it'd crash, and I would expect it to use the same amount of stack internally each time.

The documentation for GETRAND specifically suggests against calling it that way:
Quote:The sequence is seeded by the current time, so multiple calls may give identical results unless separated by at least several milliseconds. For best results, call it once per invocation of event handler function.
So if you need that many random numbers, fill an array with GETRAND instead of a single value.
It's really strange that it would cause a stack overflow though. The stack has to be exactly where it was when you called it or it'd crash, and I would expect it to use the same amount of stack internally each time.

nansenst wrote:
uint8 rand;
for(i=0;i<128;i++){
for(j=0;j<128;j++){
GETRAND(&rand)
}

From the sdk:
Prototype:
void GETRAND(byte *pDest, int nSize)
So... It is a miracle you get anywhere with that code! Unless it is just a typo and you did put a second argument of sizeof(uint8)?

nansenst wrote:
uint8 rand;
for(i=0;i<128;i++){
for(j=0;j<128;j++){
GETRAND(&rand)
}

From the sdk:
Prototype:
void GETRAND(byte *pDest, int nSize)
So... It is a miracle you get anywhere with that code! Unless it is just a typo and you did put a second argument of sizeof(uint8)?