-#ifdef __WXMAC__
- cgctx = (CGContextRef)(win_impl->GetWindow()->MacGetCGContextRef());
-#else
- cgctx = wxMacGetContextFromCurrentNSContext() ;
+ wxASSERT_MSG(win_impl->GetWindow(), "Invalid wxWindow in wxMacCoreGraphicsRenderer::CreateContext");
+ if (win_impl->GetWindow())
+ cgctx = (CGContextRef)(win_impl->GetWindow()->MacGetCGContextRef());
+#if wxOSX_USE_COCOA
+ else
+ cgctx = wxMacGetContextFromCurrentNSContext() ;