home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21050 < prev    next >
Encoding:
Text File  |  1993-01-08  |  2.9 KB  |  100 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!usc!ucla-cs!kona.cs.ucla.edu!tj
  3. From: tj@kona.cs.ucla.edu (Tom Johnson)
  4. Subject: GWorlds and Windows - a problem....
  5. Message-ID: <1993Jan8.233136.18543@cs.ucla.edu>
  6. Sender: usenet@cs.ucla.edu (Mr Usenet)
  7. Nntp-Posting-Host: kona.cs.ucla.edu
  8. Organization: UCLA, Computer Science Department
  9. Date: Fri, 8 Jan 93 23:31:36 GMT
  10. Lines: 88
  11.  
  12.  
  13. Hello-
  14.  
  15. I'm having a little bit of trouble with an offscreen world and a window.
  16.  
  17. Perhaps the easiest way to explain is to provide a small, but complete
  18. piece of source code that demonstrates the problem.  This code can be cut
  19. and pasted into a Think C 5.0.4 project w/ MacTraps.  
  20.  
  21. When WORKING is defined as TRUE, the program executes successfully.  When
  22. it is FALSE, the program crashes at the NewCWindow() call. (Note for
  23. those that try to reproduce this error:  It crashes my IIci badly enough to
  24. require a restart). 
  25.  
  26. All that is different in the working and non-working versions is the
  27. location of the NewCWindow() call.  If NewCWindow() is called before
  28. I attempt to draw into the offscreen world, everything is hunky-dory....but
  29. if I try to call NewCWindow after the drawing has occurred, NewCWindow()
  30. crashes.
  31.  
  32. Any ideas why?
  33.  
  34. I'd like to be able to create the window after I've done all my drawing, if
  35. possible.
  36.  
  37. Thanks-
  38.   Tom
  39. ------cut here-----
  40. #include <QDOffscreen.h>
  41.  
  42. #define WORKING TRUE  // change this to false to crash your mac.
  43.                       // Why does this happen?
  44. main()
  45. {
  46.    Rect        offR, windR;
  47.    WindowPtr   wind;
  48.    GWorldPtr   offWorld;
  49.    RGBColor    rgbBlack = {0,0,0};
  50.    RGBColor    rgbWhite = {65535,65535,65535};
  51.    OSErr       err;
  52.    GDHandle    SaveGD;
  53.    CGrafPtr    SavePort;
  54.  
  55.    InitGraf(&qd.thePort);
  56.    FlushEvents(everyEvent, 0);
  57.    InitWindows();
  58.    InitDialogs(nil);
  59.    InitCursor();
  60.     
  61.    offR.top = offR.left = 0;
  62.    offR.bottom = offR.right = 100;
  63.  
  64.    windR = offR;
  65.    OffsetRect(&windR, 40,40);    // move window down and over.
  66.  
  67.    GetGWorld(&SavePort, &SaveGD);
  68.  
  69.    err = NewGWorld(&offWorld, 8, &offR, nil, nil, 0);
  70.  
  71. #if WORKING    // if called here, it'll work
  72.    wind = NewCWindow(nil, &windR, "\p", TRUE, zoomDocProc, 
  73.                      (WindowPtr) -1, TRUE, 0);
  74. #endif
  75.    SetGWorld(offWorld, nil);
  76.    PaintRect(&offR);  // Just fill it w/ black
  77.  
  78. #if !WORKING    // this will crash spectacularly
  79.    wind = NewCWindow(nil, &windR, "\p", TRUE, zoomDocProc, 
  80.                      (WindowPtr) -1, TRUE, 0);
  81. #endif
  82.     
  83.    SetGWorld(SavePort, SaveGD);
  84.  
  85.    RGBForeColor(&rgbBlack);
  86.    RGBBackColor(&rgbWhite);
  87.  
  88.    CopyBits((BitMap *) *offWorld->portPixMap,
  89.             (BitMap *)&wind->portBits, 
  90.             &((**(*offWorld).portPixMap).bounds), 
  91.             &wind->portRect, srcCopy, nil);
  92.     
  93.    while (!Button())    // loop until mouse click
  94.         ;
  95. }
  96. --------------END OF FILE-----------------
  97. -- 
  98. Tom Johnson             "They say Confucious does his crossword with a pen."
  99. tj@cs.ucla.edu                               -Tori Amos
  100.