@@ -21,6 +21,13 @@ CKCanvas::CKCanvas(const CKControlInitParams& params)
2121
2222 CKPROFILE
2323
24+ this ->__gworldptr = NULL ;
25+
26+ if (!CKHasColorQuickDraw ()) {
27+ CKLog (" CKCanvas requires Color QuickDraw; offscreen drawing disabled." );
28+ return ;
29+ }
30+
2431 Rect bounds = {0 , 0 , (short )params.height , (short )params.width };
2532 OSErr err = NewGWorld (&(this ->__gworldptr ), 16 , &bounds, NULL , NULL , 0 );
2633 if (err != noErr) {
@@ -48,6 +55,10 @@ void CKCanvas::Redraw() {
4855 return ;
4956 }
5057
58+ if (!this ->__gworldptr ) {
59+ return ;
60+ }
61+
5162#ifdef CKDEBUGTIMEDRAWS
5263 long t_start = TickCount ();
5364#endif
@@ -91,6 +102,10 @@ void CKCanvas::FillRect(CKRect rect, CKColor c) {
91102
92103 CKPROFILE
93104
105+ if (!this ->__gworldptr ) {
106+ return ;
107+ }
108+
94109 RGBColor rgb = c.ToOS ();
95110 PixPatHandle pixPat = NewPixPat ();
96111 if (pixPat != NULL ) {
@@ -133,6 +148,10 @@ void CKCanvas::SetPixel(CKPoint p, CKColor c) {
133148
134149 CKPROFILE
135150
151+ if (!this ->__gworldptr ) {
152+ return ;
153+ }
154+
136155 if (p.x < 0 || p.x > this ->rect ->size ->width ) {
137156 return ;
138157 }
@@ -160,6 +179,10 @@ void CKCanvas::SetPixel(CKPoint p, CKColor c) {
160179
161180void CKCanvas::DrawLine (CKPoint start, CKPoint end, CKColor c) {
162181
182+ if (!this ->__gworldptr ) {
183+ return ;
184+ }
185+
163186 RGBColor rgb = c.ToOS ();
164187 CGrafPtr oldPort;
165188 GDHandle oldGD;
@@ -175,6 +198,10 @@ void CKCanvas::DrawLine(CKPoint start, CKPoint end, CKColor c) {
175198
176199bool CKCanvas::DrawResourceIcon (short resourceId, CKPoint where) {
177200
201+ if (!this ->__gworldptr ) {
202+ return false ;
203+ }
204+
178205 PixMapHandle offscreenPixMap = GetGWorldPixMap (this ->__gworldptr );
179206 if (!LockPixels (offscreenPixMap)) {
180207 CKLog (" Can't lock GWorldPixMap.. Purged, maybe?" );
0 commit comments