diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index 40a60953ca..5fb422ff21 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -412,6 +412,7 @@ type end; procedure SetViewDefaults(AView: NSView); +function CheckMainThread: Boolean; implementation @@ -421,6 +422,11 @@ begin AView.setAutoresizingMask(NSViewMinYMargin or NSViewMaxXMargin); end; +function CheckMainThread: Boolean; +begin + Result := NSThread.currentThread.isMainThread; +end; + { TCocoaPanel } function TCocoaPanel.windowShouldClose(sender: id): LongBool; @@ -893,7 +899,8 @@ end; procedure TCocoaCustomControl.drawRect(dirtyRect: NSRect); begin inherited drawRect(dirtyRect); - callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect); + if CheckMainThread then + callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect); end; function TCocoaCustomControl.lclGetCallback: ICommonCallback; diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index a031e7b12f..7908ec4350 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -777,7 +777,6 @@ end; function TLCLCommonCallback.DeliverMessage(var Msg): LRESULT; begin -// WriteLn('Delivering message to target: ', PtrInt(Target), ' ', Target.ClassName); Result := LCLMessageGlue.DeliverMessage(Target, Msg); end;