Saturday, April 4, 2009

Invalid Chunk Pointer when Exiting Application

This is a dreaded error message, because if it occurs only when exiting the application all the variables can look fine up to and including the last line of code, and then it crashes. Supposedly it signifies that the application is trying to free up a handle that is already free, such as a a field on a form that is already closed. Alternatively it is supposed to indicate that the application allocated too much memory for global variables. What I find is that if I allocate even local memory for a large, two dimensional char array or a structure consisting of chars, it the application crashes after AppStop on exiting. So my advice is isolate the function that reproduces the "exit crash" and rem out any large char array or char structure declarations, and the crash goes away. Then rewrite the code using more compact char arrays, such as smaller arrays or single-dimensional arrrays, recycling the same memory allocation in loops instead of spreading all the data out into large structures.

On a related note, I also get horrible crashes when editing text fields in my app. I find that usually that means I have screwed up the resizing of the memory when saving the data to the palm's memory. So look at the resizing code or the resizing functions reallly closely when that happens.

Another landmark to report today, besides figuring out the exit crashes and the edit field crashes: I now have the ability to line-by-line debug a Palm OS 5 app while it retreives data from the internet. The trick is to 1. Use the TX Simulator, 2. In Debugger Preferences import the "poser" file, 3. Right click on the Simulator, go into Settings->Communication and select "redirect NetLib calls to host TCP/IP". Now the TX Simulator is connected to the internet, even while using the debugger.

No comments:

Post a Comment