[net.micro.mac] Help: TMON purge bombs DrawString

larryh@tekcbi.UUCP (07/15/86)

I recently spent an entire weekend tracking down a problem in a program that
was drawing text into an off-screen bitmap.  The symptom was that no text
would be drawn if TMON's heap purge was on (app heap).  I finally distilled
off all the volatile fractions and was left with the tiny residue of a program
shown below.  (Can you tell that I used to be a chemist?)  To reproduce the
problem, simply turn on application heap purging at the breakpoint and also
do a "scramble now" command (using the standard user area).  The string will
not be drawn and in fact, the system will be so damaged that a reboot
is necessary.

The problem did not occur if the system font was used in place of the
application font (at least with the original, more complex program).
I suspect that the application font is being purged and DrawString is barfing
on a stale pointer but why is the GetFontInfo() necessary and why does
purging have to be done before AND during the DrawString() call?

Does anybody have any idea what is going on here?  Did I forget to init
something?  Does TMON have a bug? (I doubt it.)  Does the mac ROM have a
problem?  Help!

Configuration:  Mac+, System 3.2, Finder 5.3 (but not in use), Aztec C 1.06G
(I think), TMON (don't remember).

The Program:

#include	"quickdraw.h"
#include	"window.h"
#include	"inits.h"

WindowRecord wRecord;
WindowPtr 	myWindow;
Rect lRect;
FontInfo info;


main()
{
	InitGraf(&thePort);
	InitFonts();
	InitWindows();
	InitCursor();


/* window initialization */
	SetRect(&lRect,40,40,300,300);
	myWindow = NewWindow(&wRecord, &lRect,"\Ptest",
				0x100, 0, -1L, 0, 0L);
	SetPort(myWindow);
	ClipRect(&myWindow->portRect);
	SelectWindow(myWindow);

	GetFontInfo(&info);	/* this must be here to exibit problem */
#asm
	trap #$f		/* breakpoint to enter TMON */
#endasm
	MoveTo(20,20);
	DrawString("\PThis will not be drawn if heap purge is on");
	_exit();		/* the mac is done for at this point */
}


Larry Hutchinson, Tektronix, Inc. PO Box 500, MS 02-305, Beaverton, OR 97077
{ decvax,allegra }!tektronix!tekcbi!larryh