Hi everyone,
I've got a very strange problem with a piece of code in my prizm Add-in. I dynamically allocated 3 arrays of floats at the beginning of the method and freed them in the end, which should work fine. When I execute the program, the method works fine twice, but the third time it's called it throws an
ADDRESS(R) error on the calculator.

Code:

float* genPArrFrLArr(int* array, int size, float startingDir, int maxSize, float angle, float* points) {
...
   float* pushX = (float*) malloc(maxSize * sizeof(float));
   float* pushY = (float*) malloc(maxSize * sizeof(float));
   float* pushAngle = (float*) malloc(maxSize * sizeof(float));
...
   free(pushX);
   free(pushY);
   free(pushAngle);
}

I am 100% sure that the error occurs at these last 3 lines, because I located the error using message boxes before and after these lines. I'm sorry if this information is to vague, but the whole method (or even the whole file) is pretty messy and posting it probably wouldn't help solving the problem.
I would be very thankful if this problem could be solved.

Jamesbeans
If you reduce the function to just this do you still get an error?

I notice you're not returning anything, but you have float* as the return type. That could be causing an issue, too. Or could in the future.
I left the return line out, it's just below the free() lines. I tried to execute the method with only these 6 lines and the return statement and it threw the same error.
Check the malloc return values and cross-reference the active PC from your error message with a binary to figure out what exactly is bombing out. I suspect you're getting a NULL for some reason.
I checked the malloc return values, they're fine. I'm sorry but I don't know what you mean by "cross-reference the active PC...". Could you explain it (or give a piece of code)?
Maybe this will help http://prizm.cemetech.net/index.php/Sys_free

I think Prizm expects the above and http://prizm.cemetech.net/index.php/Sys_malloc when dealing with heap - probably need to include fxcg/heap.h header

Let us know if it helps
amazonka wrote:
syscalls
Irrelevant, aside from the "the heap kind of sucks" part.
Tari wrote:
amazonka wrote:
syscalls
Irrelevant, aside from the "the heap kind of sucks" part.

I see now - thanks. Regarding heap bugs, the following post was linked there https://www.cemetech.net/forum/viewtopic.php?t=7539 - could it be the alignment bug Kerm was referring to towards the bottom of that post?
Do you mean this post?
Quote:
The Prizm does indeed crash if you try to dereference a pointer to an integer that is not aligned on a 4-byte boundary, for instance, so I agree that this implementation seems a bit broken...

It could be this problem, but nevertheless I've got no idea how to solve it...
Jamesbeans wrote:
Do you mean this post?
Quote:
The Prizm does indeed crash if you try to dereference a pointer to an integer that is not aligned on a 4-byte boundary, for instance, so I agree that this implementation seems a bit broken...

It could be this problem, but nevertheless I've got no idea how to solve it...

Yes, but also not sure how to solve it - maybe Kerm can help
After taking a break from programming I solved the problem a few days ago. I set the size of an array down, that was completely independent from the ones mentioned in the first post, and suddenly my program ran without any problems. If I set the bits I want to malloc to higher values, the Add-In gets stuck at pretty random states. By that I mean that I stops at a different point in the emulator than in the real calculator. I've got no idea about the exact cause of the problem, but it seems to be related to the bad malloc implementation mentioned in this post. If anyone has more to say about all this stuff, I'd be interested to hear it, but my knowledge in this regard is too limited to do any deeper research.

Jamesbeans
I'm glad you solved it - i wonder if there is a dynamic way of monitoring heap somehow to force an actual exit from the addin instead of a crash by perhaps monitoring free space etc
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement