[comp.sys.mac] Obscure cursor bug

fdot@sphinx.UChicago.UUCP (Tom Lippincott) (03/16/87)

The Bug:

I have a bug in a program I'm writing which leaves cursor images lying around
the screen.  This is fine for drawing forests, but it obscures the intended
purpose of the program.


The Symptoms:

The problem occurs when I have a task in the vertical retrace queue, only
when that task calls a drawing command, and apparently only when the
interrupted process is drawing near (or possibly only under) then cursor.
Where the interrupting task is drawing has little or no effect.
It doesn't leave a cursor on every interrupt, but the frequency of the error
increases with both the frequency of the drawing in the interrupted task
and the frequency of the interrupt.  I've only tried situations where the
interrupt either always draws or never draws.  If the cursor is holding still,
and the program repeatedly draws under it, I can tell when the problem
happens because the cursor stops flickering.  Occasionally (maybe 1/300)
the cursor left behind is slightly disfigured.


The Unsuccessful Attempts:

Hiding the cursor during the interrupt (and restoring it at the end) makes the
cursor flicker, but has no effect on the bug.

I have no doubt that hiding the cursor during the interrupted process would
cure the problem, but this would make things like menu selection difficult.

The interrupt procedure saves and restores every global variable that I know
of that it changes; in particular, it saves and restores the grafport, and
has a private window of its own to draw into.


The Theory:

First, the main program issues a drawing command.
	Quickdraw realizes that the cursor is over the thing being drawn,
	hides the cursor (hence the cursor flickers when being drawn under)
	by restoring the area from an "under the cursor bitmap",
	and stores the fact that it hid the cursor in some global variable
	(which is unknown to me).

While Quickdraw is performing the actual drawing, the interrupt hits, issuing
		a drawing command elsewhere.
	Quickdraw checks whether the cursor is over the thing being drawn,
	finds that it isn't, and clears the variable that says so.
	It completes the command normally.

Next, the VBL interrupt handler calls the cursor drawing routine,
	which restores the area under the cursor (to little or no effect)
	and draws a new one

Quickdraw finishes the initial draw, saves the freshly drawn area into the
	"under the cursor" area (with the cursor), and redraws the cursor
	(this time the redrawing has little effect).

Now, the "under the cursor" area is the same as the normal screen, so
	the cursor cannot be erased.  (And the cursor can't flicker any more
	if you're holding the mouse still.)

The deformed cursors would come from Quickdraw continuing to draw over the
	cursor after the interrupt.


The Fix:

The fix by this theory would be to save and restore the cursor-hiding
variable during my interrupt.


The Request:

Help!

						--Tom Lippincott
						..ihnp4!gargoyle!sphinx!fdot

	"Thank you for observing all saftey precorpcorpc-o