I've got a custom drawing routine for an item in a table that need to draw
quite a bit of stuff, so I thought I'd modularize the code into some
different drawing functions. In the process, some calls to the following
conversion function were moved from the table callback out to the drawing
functions. This function didn't cause problems when it was called from
inside the callback routine, but if it's called from the drawing functions I
get a bus error when the calling function returns control to the table
callback routine.
static Char * SecondsToString(Char *strTime, UInt32 seconds)
{
UInt8 hours, minutes;
minutes = seconds / 60;
// round up
if (seconds % 60 >= 30) {
minutes++;
}
hours = minutes / 60;
minutes = minutes % 60;
TimeToAscii(hours, minutes, tfColon24h, strTime);
return strTime;
}
For example, if my table callback function contains this I'm OK:
static void MainFormDrawRecord(MemPtr table, Int16 row, Int16 column,
RectangleType *bounds)
{
...
Char strTime[6];
UInt32 aNumber = 10;
...
SecondsToString(strTime, aNumber);
// Drawing stuff here
}
But if I do this, I get the error:
static void MainFormDrawRecord(MemPtr table, Int16 row, Int16 column,
RectangleType *bounds)
{
...
UInt32 aNumber = 10;
...
DrawNumber(aNumber);
...
}
static void DrawNumber(UInt32 aNumber)
{
Char strTime[6];
SecondsToString(strTime, aNumber);
// Drawing stuff here
}<----BUS ERROR HAPPENS HERE
Note: the bus error happens whether I do any drawing inside the DrawNumber
function or not. All I need to do is call SecondsToString somewhere in
there and it'll crash when it tries to hand control back to the table
callback routine. I'm sure there is some stupid C mistake in what I'm
doing, but I'd appreciate someone pointing out the evil of my ways.
TIA!
David Beers
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/