Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!pyramid!voder!apple!dgold From: dgold@Apple.COM (David Goldsmith) Newsgroups: comp.sys.mac.programmer Subject: Re: Help! 'Monitors' cdev related bug. Message-ID: <7600@apple.Apple.Com> Date: 8 Mar 88 21:32:06 GMT References: <3189@tekgvs.TEK.COM> Reply-To: dgold@apple.UUCP (David Goldsmith) Organization: Apple Computer Inc, Cupertino, CA Lines: 36 Keywords: bug MacII cdev offscreen bitmap In article <3189@tekgvs.TEK.COM> larryh@tekgvs.TEK.COM (Larry Hutchinson) writes: > >Is anyone aware of problems with the 'Monitors' cdev in the current >system release? > >I have a very nasty bug in an application I am working on (or in the >'Monitors' cdev). The bug is very difficult to reproduce. >It manifests itself as a bus error when changing the number >of colors using the control panel. I am 80% sure the problem is with >my code but would like to check with you folks first. >... >I have finally found a sequence of events that will always produce >the problem and will be spending time single stepping thru the cdev >unless I get an indication from you folks that it may not be my >problem. It's almost certainly your problem. Color Quickdraw keeps a data structure called the port list which is a list of all the open grafports in the system. When you change the bit depth via Monitors, it walks the port list and updates the PixMap data structures that they refer to (assuming they refer to the screen) to reflect the new bit depth. Ways in which a crash can occur are if you improperly maintain your GrafPorts or if a GrafPort contains garbage (such as an invalid PixMap handle). One common error is to keep a GrafPort in a handle. This doesn't work. If a GrafPort moves between OpenPort and ClosePort, the port list is pointing at garbage. Another is to dispose of a port via DisposPtr without doing a ClosePort first. Again, the port list is corrupted. GrafPorts are non- relocatable objects which must be properly maintained. From what you say, I suspect your problem arises from the empty handle which you have stuffed in the grafport. The handle must be a valid PixMap data structure. In general, messing around with data structures behind the ROM's back is a good way to run into trouble in the present or the future. There are routines for setting and retrieving the port's pixmap, and for creating new pixmaps from scratch; these are better to use then mucking with stuff directly.