Path: utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!kth!draken!tut!santra!kampi.hut.fi!jmunkki
From: jmunkki@kampi.hut.fi (Juri Munkki)
Newsgroups: comp.sys.mac.programmer
Subject: A *** SERIOUS *** (but small) BUG IN SUITCASE II!
Message-ID: <24320@santra.UUCP>
Date: 8 Aug 89 22:35:43 GMT
References: <21867@andante.UUCP>
Sender: news@santra.UUCP
Reply-To: jmunkki@kampi.hut.fi (Juri Munkki)
Organization: Helsinki University of Technology, Finland
Lines: 49

I just discovered that I had wasted several weeks hunting down a bug in
my source code, when it actually wasn't there. The problem was that somehow
the system was using grafports that didn't exist.

I always use the sequence:
	GetPort(&saved);
	SetPort(someport);
	...
	SetPort(saved);

This means that when InitWindows sets the port to the window manager port,
it usually remains that way for the rest of my program. I verified this
with a debugger.

I then proceeded to start with Suitcase II (v 1.2.2) enabled and the
behavior changed. Whenever I opened a desk accessory, the port would
change to that window. The problem is that when the desk accessory is
closed, the port (thePort for you programmers) stays in that now
defunct window.

You might say that this does not matter, because everyone calls SetPort
before doing any _drawing_. The problem arises when some programs
create regions or pictures and just assume that it's fine to use any
port (in a storm?). The Blast FKEY is a good example, since the source
code was published in MacTutor. Even the window manager might do this,
but I haven't checked this.

This bug might affect any really well behaved application. Imagine my
anger when I discovered that I follow all the apple guidelines and even
a few of my own and that my software has a problem with desk accessories!

The first fix that came to my mind was to change ports every time one of
windows is activated or deactivated. This doesn't solve the problem when
there are no windows open. Any bright suggestions? I don't want to call
SetPort every time I go through the event loop, but I just might have to
do that...Suitcase is too popular to be ignored.

Please check your own source code. Even if you don't restore your grafports,
it is possible (although highly unlikely) that your code will crash in some
situations.

I would really like to get some feedback on this. If you do not want to post,
please feel free to mail me. (If jmunkki@hut.fi doesn't work, try mcvax!santra!
jmunkki)

_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
|     Juri Munkki jmunkki@hut.fi  jmunkki@fingate.bitnet        I Want   Ne   |
|     Helsinki University of Technology Computing Centre        My Own   XT   |
^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^