home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!usc!ucla-cs!kona.cs.ucla.edu!tj
- From: tj@kona.cs.ucla.edu (Tom Johnson)
- Subject: GWorlds and Windows - a problem....
- Message-ID: <1993Jan8.233136.18543@cs.ucla.edu>
- Sender: usenet@cs.ucla.edu (Mr Usenet)
- Nntp-Posting-Host: kona.cs.ucla.edu
- Organization: UCLA, Computer Science Department
- Date: Fri, 8 Jan 93 23:31:36 GMT
- Lines: 88
-
-
- Hello-
-
- I'm having a little bit of trouble with an offscreen world and a window.
-
- Perhaps the easiest way to explain is to provide a small, but complete
- piece of source code that demonstrates the problem. This code can be cut
- and pasted into a Think C 5.0.4 project w/ MacTraps.
-
- When WORKING is defined as TRUE, the program executes successfully. When
- it is FALSE, the program crashes at the NewCWindow() call. (Note for
- those that try to reproduce this error: It crashes my IIci badly enough to
- require a restart).
-
- All that is different in the working and non-working versions is the
- location of the NewCWindow() call. If NewCWindow() is called before
- I attempt to draw into the offscreen world, everything is hunky-dory....but
- if I try to call NewCWindow after the drawing has occurred, NewCWindow()
- crashes.
-
- Any ideas why?
-
- I'd like to be able to create the window after I've done all my drawing, if
- possible.
-
- Thanks-
- Tom
- ------cut here-----
- #include <QDOffscreen.h>
-
- #define WORKING TRUE // change this to false to crash your mac.
- // Why does this happen?
- main()
- {
- Rect offR, windR;
- WindowPtr wind;
- GWorldPtr offWorld;
- RGBColor rgbBlack = {0,0,0};
- RGBColor rgbWhite = {65535,65535,65535};
- OSErr err;
- GDHandle SaveGD;
- CGrafPtr SavePort;
-
- InitGraf(&qd.thePort);
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitDialogs(nil);
- InitCursor();
-
- offR.top = offR.left = 0;
- offR.bottom = offR.right = 100;
-
- windR = offR;
- OffsetRect(&windR, 40,40); // move window down and over.
-
- GetGWorld(&SavePort, &SaveGD);
-
- err = NewGWorld(&offWorld, 8, &offR, nil, nil, 0);
-
- #if WORKING // if called here, it'll work
- wind = NewCWindow(nil, &windR, "\p", TRUE, zoomDocProc,
- (WindowPtr) -1, TRUE, 0);
- #endif
- SetGWorld(offWorld, nil);
- PaintRect(&offR); // Just fill it w/ black
-
- #if !WORKING // this will crash spectacularly
- wind = NewCWindow(nil, &windR, "\p", TRUE, zoomDocProc,
- (WindowPtr) -1, TRUE, 0);
- #endif
-
- SetGWorld(SavePort, SaveGD);
-
- RGBForeColor(&rgbBlack);
- RGBBackColor(&rgbWhite);
-
- CopyBits((BitMap *) *offWorld->portPixMap,
- (BitMap *)&wind->portBits,
- &((**(*offWorld).portPixMap).bounds),
- &wind->portRect, srcCopy, nil);
-
- while (!Button()) // loop until mouse click
- ;
- }
- --------------END OF FILE-----------------
- --
- Tom Johnson "They say Confucious does his crossword with a pen."
- tj@cs.ucla.edu -Tori Amos
-