Aaron Ardiri wrote:
> ok.. i think this is a gcc problem.
More likely it is caused by Y2K, Hackmaster and the fact that Jesus
was nailed to the wrong side of the cross.
Even more likely still is that it is programmer error. :-)
> when i compile the source code with gcc, the program runs, and
> no double buffering occurs - but as soon as i exit the program,
> i get a system crash. (requiring reset).
Events are the heart of PalmOS programming, and learning event-driven
programming is the major requirement for good PalmOS programming.
Events are like snail mail - you do what you like with those intended
for you, but you pass on those not meant for your eyes. Your code is
a gross violation of the Postal Act :-)
Here is a lightly annotated version of your event loop.
My comments in between <>
-----------------------------------------------------
do {
< 0 used to generate frequent nilEvents for animation- that's OK >
EvtGetEvent(&event, 0);
if (event.eType == frmLoadEvent) {
< USUAL frmLoadEvent CODE SNIPPED >
}
else {
< For __EVERY__ other event type .............. NOT just nilEvent >
< and WITHOUT checking the graphics form is still current >
_Graphics_clearScr();
_Cube3D_draw(newCube, NORMAL);
dx += 2; dy += 1; dz += 3;
newCube = _Cube3D_rotate(cube, dx % 360, dy % 360, dz % 360);
_Graphics_repaint();
}
< What is this doing down here? SysHandleEvent should be called
straight after EvtGetEvent according to the docs (except in
special cases that are not applicable to your application) >
if (!SysHandleEvent(&event))
if (!MenuHandleEvent(0, &event, &error))
FrmDispatchEvent(&event);
} while (event.eType != appStopEvent);
------------------------------------------------------
Your graphics code is called on EVERY event, bar one. So it is
valiantly trying to spin cubes as even frmCloseEvent and appStopEvent
are called. Talk about obnoxious code :) Perhaps there's a reason for
the crash you get on exit? :)
It probably should be in your Form handler, and DEFINITELY should be
after an "IF EVENT==nilEvent" type of statement.
Furthermore, your graphics 'library' is not even writing to the form
you display. You call the initialise function before entering the
event loop - so before your form is loaded and displayed. Yet the
init function stores away the (then) current draw window and later
uses that as the window to write to.
I don't use gcc so I won't be debugging your code further.
I thought I'd post this to defend the gcc writers, and on behalf of
any students you dare to fail in the Programming In C course you are
lecturing :-)
Keep up the PalmOS programming, just don't go blaming the tools for
your mistakes. They work. You are writing to a forum with many people
successfully using these tools.
Murray Dowling
Deskfree Computing
http://www.deskfree.com/