[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drawing to offscreen bitmap bombs



Tom McDougal writes about a piece of code that crashes under MCL2.0p2
when he attempts to create a port and set the port bits.

Here is the old code:
(defvar *bitmap-1* (make-bitmap 0 0 200 200))
(rlet ((port :grafport))
  (unwind-protect
    (without-interrupts
     (#_openPort port)
     (with-port port
       (#_setPortBits *bitmap-1*)
       (#_moveTo 20 20)
       (#_lineTo 70 30)))
    (#_closePort port)))

Here's what happens when you do a variant of the code
without creating a new port and using the port associated
with an existing window

(setq that (make-instance 'window))
(defvar *bitmap-1* (make-bitmap 0 0 200 200))
(with-focused-view that
  (window-select that)
  (with-port (wptr that)
    (#_setPortBits *bitmap-1*)
    (#_moveTo 20 20)
    (#_lineTo 70 30)))

1. The close-box has no effect but the File close menu item does work.
2. The window resize box disappears when you resize it and the boundaries
   seem to be a bit off. The title bar also disappears along with
   the zoom icon and the close box.

Most probably what is happening in the original code
is that the port fields have not been initialized. The
fields are filled with the current contents of memory.
The graphic procs probably point to totally invalid code.
Thus the crashes are not unexpected.
The quickdrawing calls will fail! To use the port,
fill in the appropriate fields. Alternatively, use the
qdoffscreen routines to create offscreen bit maps.

mark

Here's the result of printing a valid port record
? (print-record (rref  (wptr that) :windowrecord.port) :grafport)

#<Record :GRAFPORT :DEVICE 0 
:PORTBITS #<Record :BITMAP :BASEADDR #<A Mac Non-zone Pointer #xF9900020> 
:ROWBYTES 80 
:BOUNDS #<Record :RECT :TOP -44 :LEFT -6 :BOTTOM 436 :RIGHT 634>> 
:PORTRECT #<Record :RECT :TOP 0 :LEFT 0 :BOTTOM 216 :RIGHT 479> 
:VISRGN #<A Mac Handle, Unlocked, Size 52 #x15B718> 
:CLIPRGN #<A Mac Handle, Unlocked, Size 10 #x15B74C> 
:BKPAT #<Record :PATTERN :ARRAY #<A Mac Non-zone Pointer #x15B534>> 
:FILLPAT #<Record :PATTERN :ARRAY #<A Mac Non-zone Pointer #x15B53C>> 
:PNLOC #@(0 0) :PNSIZE #@(1 1) :PNMODE 8 
:PNPAT #<Record :PATTERN :ARRAY #<A Mac Non-zone Pointer #x15B54E>> 
:PNVIS 0 :TXFONT 4 :TXFACE 0 :TXMODE 1 :TXSIZE 9 
:SPEXTRA 0 :FGCOLOR 33 :BKCOLOR 30 
:COLRBIT 0 :PATSTRETCH 0 :PICSAVE #<A Null Mac Pointer> 
:RGNSAVE #<A Null Mac Pointer> :POLYSAVE #<A Null Mac Pointer> 
:GRAFPROCS #<A Null Mac Pointer>>

Here's the result of printing an uninitialized record:

? (setq port (make-record :grafport))
#<A Mac Zone Pointer Size 108 #x15BAD8>
? (print-record port :grafport)

#<Record :GRAFPORT :DEVICE 10 
:PORTBITS #<Record :BITMAP :BASEADDR #<A Null Mac Pointer> 
:ROWBYTES 0 
:BOUNDS #<Record :RECT :TOP 0 :LEFT 100 :BOTTOM 0 :RIGHT 32>> 
:PORTRECT #<Record :RECT :TOP 20 :LEFT -14992 :BOTTOM 0 :RIGHT 1> 
:VISRGN #<A Mac Non-zone Pointer #x1>
 :CLIPRGN #<A Mac Non-zone Pointer #xFFFF> 
:BKPAT #<Record :PATTERN :ARRAY #<A Mac Non-zone Pointer #x15BAF8>> 
:FILLPAT #<Record :PATTERN :ARRAY #<A Mac Non-zone Pointer #x15BB00>> 
:PNLOC #@(393 32767) :PNSIZE #@(548 44) :PNMODE 32767 
:PNPAT #<Record :PATTERN :ARRAY #<A Mac Non-zone Pointer #x15BB12>> 
:PNVIS -14992 :TXFONT 44 :TXFACE 0 :TXMODE 0 :TXSIZE 67 
:SPEXTRA 31916086 :FGCOLOR 487 :BKCOLOR 2147418167 
:COLRBIT 1 :PATSTRETCH 486 :PICSAVE #<A Mac Non-zone Pointer #x7FFF0042> 
:RGNSAVE #<A Mac Non-zone Pointer #x101E6> 
:POLYSAVE #<A Mac Non-zone Pointer #x7FFF0043> 
:GRAFPROCS #<A Mac Non-zone Pointer #x1E7>>