Path: utzoo!mnetor!uunet!husc6!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!tektronix!tekcrl!tekgvs!larryh From: larryh@tekgvs.TEK.COM (Larry Hutchinson) Newsgroups: comp.sys.mac.programmer Subject: Re: Help! 'Monitors' cdev related bug. Message-ID: <3193@tekgvs.TEK.COM> Date: 8 Mar 88 16:40:26 GMT References: <3189@tekgvs.TEK.COM> Reply-To: larryh@tekgvs.UUCP (Larry Hutchinson) Organization: Tektronix, Inc., Beaverton, OR. Lines: 37 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. Well, I couldn't wait for responses and did some more single stepping thru the cdev code and found the bug. It was indeed my fault but I think you will find the result interresting and instructive. It turns out that the problem was lurking in my code for almost a year. I had embedded a GrafPort in a relocateable structure. Now, don't everyone go 'Ooooh' at once! -- I always locked the structure when the port was in use. In traceing thru the cdev code, I discovered that it sequences thru an array of GrafPtrs and does an InitPalette or some such on any CGrafPorts that it finds. I was unaware that this list of GrafPorts existed. (You can find it via a Handle to the list stored at 0xD66 (PortList) the first word is the count of GrafPtrs in the list) The address placed in this list was where the port was when I did an OpenPort on it but since it was allowed to move between uses, the address became invalid. Another way one could run into this problem is if one forgets to do a ClosePort when finished with a port. IM warns that the memory allocated to a few handles will be lost but this cdev stuff is more serious. Let that be a lesson to me! Larry Hutchinson, Tektronix, Inc. PO Box 500, MS 50-383, Beaverton, OR 97077 UUCP: [uunet|ucbvax|decvax|ihnp4|hplabs]!tektronix!tekgvs!larryh ARPA: larryh%tekgvs.TEK.COM@RELAY.CS.NET CSNet: larryh@tekgvs.TEK.COM