This simpliest test app (for aarch64) crashes on Mac with Apple M1.
Can you help? Initially this problem occured in my main app with Metal graphics. Now I reproduced it with a simple test app (36 lines).
FPC 3.2.1 fixes + Lazarus 2.0.10 on Intel Mac Big Sur + Xcode 12.2.
This test app runs fine on Apple DTK (aarch64 version) and on any Intel Mac (x86-64). And crashes on M1 (aarch64) even with no optimizations (O0).
program SimpleApp;
{$mode objfpc}
{$modeswitch objectivec1}
uses
CocoaAll, MacOSAll;
type
TMyWndDelegate = objcclass(NSObject, NSWindowDelegateProtocol)
function windowShouldClose (sender: id): ObjCBOOL; message 'windowShouldClose:';
end;
var
App: NSApplication;
Wnd: NSWindow;
wDeleg: TMyWndDelegate;
function TMyWndDelegate.windowShouldClose (sender: id): ObjCBOOL;
begin
Result:=True;
App.terminate(sender);
end;
begin
App:=NSApplication.sharedapplication;
App.finishLaunching;
Wnd:=NSWindow.alloc.initWithContentRect_styleMask_backing_defer(NSMakeRect(0, 0, 10, 10),
NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask,
NSBackingStoreBuffered, False);
wDeleg:=TMyWndDelegate.alloc.init;
Wnd.setDelegate(wDeleg);
Wnd.setFrame_display(NSMakeRect(200,200,400,300), True);
Wnd.makeKeyandOrderFront(nil);
App.run;
end.
It crashes on creating of NSWindow initWithContentRect_styleMask_backing_defer()
Dec 8 05:37:07 Toms-Mac-mini com.apple.xpc.launchd[1]: Coalition Cache Hit: app<application.SimpleApp.2109617.2109623(501)> [14248]
Dec 8 05:37:09 Toms-Mac-mini com.apple.xpc.launchd[1] (application.SimpleApp.2109617.2109623[14271]): Service exited with abnormal code: 217
Full source code is attached.
If you try to replace all StyleMask parameters in initWithContentRect_styleMask_backing_defer() with 0 (zero), this function will work. But then app crashes on this line:
device:=MTLCreateSystemDefaultDevice; (we initialize Metal graphics)
UPD. This problem doesn't appear with fpc 3.3.1 trunk.