Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!csd4.milw.wisc.edu!bbn!apple!shebanow From: shebanow@Apple.COM (Andrew Shebanow) Newsgroups: comp.sys.mac.programmer Subject: Re: Stack manipulation problems Message-ID: <23979@apple.Apple.COM> Date: 14 Jan 89 21:19:01 GMT References: Organization: Apple Computer Inc, Cupertino, CA Lines: 21 What you are experiencing is a common problem encountered by people trying to implement multiple threads of execution within a single Mac application. The problem is that QuickDraw (and certain Memory Manager calls) use the stack to store temporary data. They determine how much space is available by subtracting the top of the application heap from the current stack pointer. Since your stack pointer is INSIDE of your heap, you get a very large negative number for stack size. QuickDraw then proceeds to wipe some amount of memory doing its drawing. Depending on where your stack is, and how much stack QuickDraw thinks it has, all sorts of bad things can happen. The workaround is to switch to the main stack BEFORE calling any Mac traps. You can do this by a) patching the A-TRAP dispatcher or b) using glue for all traps. Andrew Shebanow Macintosh Developer Technical Support Apple Computer