+#ifdef wxUSE_THREADS
+ // OS X starts a NSUIHeartBeatThread for animating the default button in a
+ // dialog. This causes a drawRect of the active dialog from outside the
+ // main UI thread. This causes an occasional crash since the wx drawing
+ // objects (like wxPen) are not thread safe.
+ //
+ // Notice that NSUIHeartBeatThread seems to be undocumented and doing
+ // [NSWindow setAllowsConcurrentViewDrawing:NO] does not affect it.
+ if ( !wxThread::IsMain() )
+ {
+ // just call the superclass handler, we don't need any custom wx drawing
+ // here and it seems to work fine:
+ wxOSX_DrawRectHandlerPtr
+ superimpl = (wxOSX_DrawRectHandlerPtr)
+ [[self superclass] instanceMethodForSelector:_cmd];
+ superimpl(self, _cmd, rect);
+ return;
+ }
+#endif // wxUSE_THREADS
+