Recent

Author Topic: SDL2: Runtime Error 216 on MacOS-arm  (Read 2027 times)

mischi

  • Full Member
  • ***
  • Posts: 178
SDL2: Runtime Error 216 on MacOS-arm
« on: January 12, 2025, 10:33:57 pm »
Hi.

In a minimal SDL2 program SDL_CreateWindow creates Runtime Error 216 on macOS-arm (macOS 15.2). The attachment is a minimal stripped down version, which still creates the error. Any modification I could imagine, including a complete declaration of PSDL_Window, did not change anything and I am at the end of wisdom. Any hints are welcome. Does the example run on other platforms? A corresponding example in C runs without problems.

SDL2 is installed using MacPorts and resides in /opt/local. The command to compile the example is:

Log:
michael@Hal-9001 Pascal % fpc Test1.pas -Fl/opt/local/lib
Free Pascal Compiler version 3.2.2 [2024/11/27] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Darwin for AArch64
Compiling Test1.pas
Assembling test1
Linking Test1
ld: warning: ignoring duplicate libraries: '-lc'
45 lines compiled, 0.1 sec
michael@Hal-9001 Pascal % ./Test1                                 
Runtime error 216 at $0000000189880F50
  $0000000189880F50
  $000000018987F334
  $000000018987EEB4
  $000000018987EB3C
  $0000000189AD23F4
  $0000000102806528
  $00000001027EB66C
  $0000000102460D08

TRon

  • Hero Member
  • *****
  • Posts: 3979
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #1 on: January 13, 2025, 01:56:39 am »
Is there a particular reason to use your own defines library headers and not use the standard SDL2 units.

Does the example code work with the standard headers ?

Did you also install opengl ?
I do not have to remember anything anymore thanks to total-recall.

Seenkao

  • Hero Member
  • *****
  • Posts: 652
    • New ZenGL.
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #2 on: January 13, 2025, 02:33:07 am »
Did you also install opengl ?
Разве надо на Mac надо включать OpenGL? На нём вроде по умолчанию идёт.

Google translate:
Do you really need to enable OpenGL on a Mac? It seems to work by default.


mischi, включите отладочную информацию в проекте, тогда может более точную ошибку увидите.

Google translate:
mischi, enable debug information in the project, then maybe you will see a more precise error.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

TRon

  • Hero Member
  • *****
  • Posts: 3979
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #3 on: January 13, 2025, 02:52:21 am »
Do you really need to enable OpenGL on a Mac? It seems to work by default.
I have no idea what opengl library version SDL expects or what OpenGL auxiliary libraries SDL depends on for a mac.

You might be perfectly right that this does not matter for a mac but, I honestly don't know.

@mischi:
Besides the request from Seenkao to enable debug (which can be a bit tricky for a mac: requires external debug symbols and a particular debug format) some output along the way might be able to help as well. Right now there is no hint whatsoever at what function exactly the code fails.
I do not have to remember anything anymore thanks to total-recall.

mischi

  • Full Member
  • ***
  • Posts: 178
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #4 on: January 13, 2025, 10:19:37 am »
Is there a particular reason to use your own defines library headers and not use the standard SDL2 units.

Does the example code work with the standard headers ?

Did you also install opengl ?
The error showed up using the standard SDL2 units. The only reason for having my own library headers is to reduce the level of complexity of the example. OpenGL is part of macOS as Seenkao mentioned.

mischi

  • Full Member
  • ***
  • Posts: 178
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #5 on: January 13, 2025, 10:25:05 am »
Do you really need to enable OpenGL on a Mac? It seems to work by default.
I have no idea what opengl library version SDL expects or what OpenGL auxiliary libraries SDL depends on for a mac.

You might be perfectly right that this does not matter for a mac but, I honestly don't know.

@mischi:
Besides the request from Seenkao to enable debug (which can be a bit tricky for a mac: requires external debug symbols and a particular debug format) some output along the way might be able to help as well. Right now there is no hint whatsoever at what function exactly the code fails.

Log with debug switched on:

michael@Hal-9001 Pascal % fpc -gw2 -gl Test1.pas -Fl/opt/local/lib
Free Pascal Compiler version 3.2.2 [2024/11/27] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Darwin for AArch64
Compiling Test1.pas
Assembling test1
Linking Test1
ld: warning: ignoring duplicate libraries: '-lc'
45 lines compiled, 0.3 sec
michael@Hal-9001 Pascal % lldb Test1
(lldb) target create "Test1"
Current executable set to '/Users/michael/Developer/SDL2 Trial/Pascal/Test1' (arm64).
(lldb) run
Process 7693 launched: '/Users/michael/Developer/SDL2 Trial/Pascal/Test1' (arm64)
2025-01-13 10:16:48.226151+0100 Test1[7693:22258102] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600000bb0600> F8BB1C28-BAE8-11D6-9C31-00039315CD46
Process 7693 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=1, subcode=0x1e683920)
    frame #0: 0x0000000189880f50 AppKit`_NSGetCGFloatAppConfig + 216
AppKit`_NSGetCGFloatAppConfig:
->  0x189880f50 <+216>: fsub   d0, d9, d8
    0x189880f54 <+220>: fneg   d1, d0
    0x189880f58 <+224>: fcmp   d0, #0.0
    0x189880f5c <+228>: fcsel  d10, d1, d0, mi
Target 0: (Test1) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=1, subcode=0x1e683920)
  * frame #0: 0x0000000189880f50 AppKit`_NSGetCGFloatAppConfig + 216
    frame #1: 0x000000018a3612fc AppKit`NSWindowResolvedScaleFactor + 484
    frame #2: 0x000000018987f334 AppKit`-[NSWindow _commonInitFrame:styleMask:backing:defer:] + 288
    frame #3: 0x000000018987eeb4 AppKit`-[NSWindow _initContent:styleMask:backing:defer:contentView:] + 876
    frame #4: 0x000000018987eb3c AppKit`-[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
    frame #5: 0x0000000189ad23f4 AppKit`-[NSWindow initWithContentRect:styleMask:backing:defer:screen:] + 24
    frame #6: 0x00000001004ce528 libSDL2-2.0.0.dylib`Cocoa_CreateWindow + 528
    frame #7: 0x00000001004b366c libSDL2-2.0.0.dylib`SDL_CreateWindow_REAL + 1200
    frame #8: 0x0000000100000d0c Test1`PASCALMAIN at Test1.pas:37:13
    frame #9: 0x000000010002c140 Test1`FPC_SysEntry + 32
    frame #10: 0x0000000100000c10 Test1`FPC_SYSTEMMAIN + 80
    frame #11: 0x0000000100000c68 Test1`main(ARGC=1, ARGV=0x000000016fdff5e8, ARGP=0x000000016fdff5f8) + 40
    frame #12: 0x000000018589c274 dyld`start + 2840


Seenkao

  • Hero Member
  • *****
  • Posts: 652
    • New ZenGL.
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #6 on: January 13, 2025, 10:45:41 am »
AppKit`_NSGetCGFloatAppConfig:
->  0x189880f50 <+216>: fsub   d0, d9, d8
    0x189880f54 <+220>: fneg   d1, d0
    0x189880f58 <+224>: fcmp   d0, #0.0
    0x189880f5c <+228>: fcsel  d10, d1, d0, mi
this is what i found
https://github.com/DynamoRIO/dynamorio/issues/5023

mischi, попробуйте другим способом использовать OpenGL (с другими библиотеками), возможно в них не будет данной ошибки.

Google translate:
mischi, try using OpenGL in a different way (with other libraries), perhaps they will not have this error.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

mischi

  • Full Member
  • ***
  • Posts: 178
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #7 on: January 13, 2025, 11:12:46 am »
It would be nice, if someone could run the example on macOS-x86_64.

Seenkao

  • Hero Member
  • *****
  • Posts: 652
    • New ZenGL.
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #8 on: January 13, 2025, 11:24:01 am »
It would be nice, if someone could run the example on macOS-x86_64.
мои демонстрации работают на Mac Ventura с использованием OpenGL. Но на ARM (aarch64) я их не проверял... Я использую ZenGL.
(я ещё не собрал необходимые библиотеки для ARM, пока не могу понять как это сделать на x86-64 машине).

Google translate:
my demos work on Mac Ventura using OpenGL. But I haven't tested them on ARM (aarch64)... I use ZenGL.
(I haven't yet compiled the necessary libraries for ARM, and I can't figure out how to do this on an x86-64 machine).
« Last Edit: January 13, 2025, 11:26:22 am by Seenkao »
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

mischi

  • Full Member
  • ***
  • Posts: 178
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #9 on: January 13, 2025, 02:11:35 pm »
I do not think that OpenGL is a problem. 1) Nothing OpenGL related shows up in the backtrace. 2) I have a demo written in C doing the same and some more (Show a png image in the window) and that works fine.

Can you run my example on your Mac? Either as it is or with standard SDL2.

mischi

  • Full Member
  • ***
  • Posts: 178
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #10 on: January 14, 2025, 08:05:51 pm »
Update: I tried basically the same from a Fortran program using gfortran. This works. Is this a hint that fpc is doing something unwanted?

MiSchi.

fcu

  • Full Member
  • ***
  • Posts: 111
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #11 on: January 15, 2025, 09:48:11 am »
can you try this :
Code: Pascal  [Select][+][-]
  1.  
  2. Program Test1;
  3. uses math;
  4. const
  5.   {$IFDEF WINDOWS}
  6.     SDL_LibName = 'SDL2.dll';
  7.   {$ENDIF}
  8.   {$IFDEF UNIX}
  9.     {$IFDEF DARWIN}
  10.       SDL_LibName = 'libSDL2.dylib';
  11.       {$linklib libSDL2}
  12.       {$PASCALMAINNAME SDL_main}
  13.         {$ELSE}
  14.           SDL_LibName = 'libSDL2.so';
  15.     {$ENDIF}
  16.   {$ENDIF}
  17.   SDL_INIT_VIDEO           = $00000020;
  18.   SDL_WINDOWPOS_CENTERED   = $2FFF0000;
  19.   SDL_WINDOW_OPENGL        = 2;
  20. type
  21.   SInt32 = Int32;
  22.   PSDL_Window = Pointer;
  23. var
  24.   window: PSDL_Window;
  25.   OldMask, NewMask: TFPUExceptionMask;
  26. function SDL_Init(flags: UInt32): SInt32 cdecl; external SDL_LibName;
  27. function SDL_GetError: pchar cdecl; external SDL_LibName;
  28. function SDL_CreateWindow(title: pchar; x, y, w, h: SInt32; flags: Uint32): PSDL_Window cdecl; external SDL_LibName;
  29. procedure SDL_DestroyWindow(window: PSDL_Window) cdecl; external SDL_LibName;
  30. procedure SDL_Quit cdecl; external SDL_LibName;
  31.  
  32. begin
  33.  OldMask := Math.GetExceptionMask();
  34.  NewMask := OldMask;
  35.  Include(NewMask, exInvalidOp);
  36.  Include(NewMask, exZeroDivide);
  37.  Math.SetExceptionMask(NewMask);
  38.  
  39.   if (SDL_Init(SDL_INIT_VIDEO) < 0) then
  40.   begin
  41.     writeln ('Error SDL2 Initialization: ', SDL_GetError);
  42.   end;
  43.  
  44.   window := SDL_CreateWindow('First program', SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL);
  45.   if (window = nil) then
  46.   begin
  47.     writeln ('Error window creation: ', SDL_GetError);
  48.   end;
  49.   Math.SetExceptionMask(OldMask);
  50.   SDL_DestroyWindow(window);
  51.   SDL_Quit;
  52. end.
  53.  
  54.  

mischi

  • Full Member
  • ***
  • Posts: 178
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #12 on: January 15, 2025, 11:31:41 am »
Tried:

michael@Hal-9001 Pascal % ./Test1
An unhandled exception occurred at $000000010EAF1480:
EAccessViolation: Access violation
  $000000010EAF1480
  $0000000190C4592C
  $0000000190C45390
  $0000000185A695B4
  $0000000185A78E08
  $0000000190C45480
  $0000000190C45C14
  $0000000190AB6820
  $000000018A5C9DB0
  $000000018A5C84A8
  $000000018A5C8208
  $000000018A5C7C44
  $000000018A3C91A8
  $000000018995BD44
  $000000018987F618
  $000000018987EEB4
  $000000018987EB3C

Backtrace from debugger:

(lldb) bt
* thread #1, queue = 'com.Metal.DeviceDispatch', stop reason = EXC_BAD_INSTRUCTION (code=1, subcode=0x1e220800)
  * frame #0: 0x000000010e45d480 AGXMetal13_3`AGX::SamplerStateEncoderGen4<AGX::G13::TextureFormatTable>::SamplerStateFields::SamplerStateFields(AGX::SamplerDescriptor const&) + 136
    frame #1: 0x000000010e44ca78 AGXMetal13_3`-[AGXG13GFamilyDevice initWithAcceleratorPort:simultaneousInstances:] + 2796
    frame #2: 0x000000010e4510f0 AGXMetal13_3`-[AGXG13GDevice initWithAcceleratorPort:] + 52
    frame #3: 0x0000000190c4592c Metal`-[MTLIOAccelService initWithAcceleratorPort:deviceClass:] + 492
    frame #4: 0x0000000190c45390 Metal`-[MTLIOAccelServiceGlobalContext registerService:deviceClass:] + 156
    frame #5: 0x0000000185a695b4 libdispatch.dylib`_dispatch_client_callout + 20
    frame #6: 0x0000000185a78e08 libdispatch.dylib`_dispatch_lane_barrier_sync_invoke_and_complete + 56
    frame #7: 0x0000000190c45480 Metal`-[MTLIOAccelServiceGlobalContext processPendingCreateIOAccelServiceRequests] + 184
    frame #8: 0x0000000190c45c14 Metal`MTLRegisterDevices + 116
    frame #9: 0x0000000190ab6820 Metal`MTLCopyAllDevices + 24
    frame #10: 0x000000018a5c9db0 AppKit`-[NSCGSWindow _createContext] + 344
    frame #11: 0x000000018a5c84a8 AppKit`-[NSCGSWindow _createRootLayerAndContextIfNeededUsingAsyncBehavior:] + 584
    frame #12: 0x000000018a5c8208 AppKit`-[NSCGSWindow initWithConnectionID:flags:] + 276
    frame #13: 0x000000018a5c7c44 AppKit`+[NSCGSWindow(NSCGSWindowCreation) windowWithConnectionID:flags:] + 52
    frame #14: 0x000000018a3c91a8 AppKit`_NXCreateWindow + 428
    frame #15: 0x000000018995bd44 AppKit`-[NSWindow _commonAwake] + 672
    frame #16: 0x000000018987f618 AppKit`-[NSWindow _commonInitFrame:styleMask:backing:defer:] + 1028
    frame #17: 0x000000018987eeb4 AppKit`-[NSWindow _initContent:styleMask:backing:defer:contentView:] + 876
    frame #18: 0x000000018987eb3c AppKit`-[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
    frame #19: 0x0000000189ad23f4 AppKit`-[NSWindow initWithContentRect:styleMask:backing:defer:screen:] + 24
    frame #20: 0x000000010057a528 libSDL2-2.0.0.dylib`Cocoa_CreateWindow + 528
    frame #21: 0x000000010055f66c libSDL2-2.0.0.dylib`SDL_CreateWindow_REAL + 1200
    frame #22: 0x0000000100001dc0 Test1`PASCALMAIN at Test1.pas:46:13
    frame #23: 0x000000010002d200 Test1`FPC_SysEntry + 32
    frame #24: 0x0000000100001c30 Test1`FPC_SYSTEMMAIN + 80
    frame #25: 0x0000000100001c88 Test1`main(ARGC=1, ARGV=0x000000016fdff5c8, ARGP=0x000000016fdff5d8) + 40
    frame #26: 0x000000018589c274 dyld`start + 2840

mischi

  • Full Member
  • ***
  • Posts: 178
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #13 on: January 15, 2025, 12:13:23 pm »
After adding the exception "exOverflow", it worked. The exception "exZeroDivide" could then be removed. Thanks for this.
Can the code remain like this or is there a way to fix this properly? Does this hint to a bug in libSDL2?

fcu

  • Full Member
  • ***
  • Posts: 111
Re: SDL2: Runtime Error 216 on MacOS-arm
« Reply #14 on: January 15, 2025, 05:32:20 pm »
i think its fpc bug , i run into this situation with win10 64bits & sdl2 & fpc , i did try with other languages on this system and every thing works fine except fpc 

 

TinyPortal © 2005-2018