Mac M1 SDL crash when creating a new window

SDL seems to be totally failing on my new M1 (12.2.1) when doing native builds. Here is a call stack from a crash when trying to create a new window. I’m familiar with macOS development and this crash makes no sense to me.

Any ideas how this can debugged?

CFNumberCreate (@CFNumberCreate:114)
-[NSPlaceholderNumber initWithDouble:] (@-[NSPlaceholderNumber initWithDouble:]:18)
+[CALayer defaultValueForKey:] (@+[CALayer defaultValueForKey:]:232)
classDescription_locked(objc_class*) (@classDescription_locked(objc_class*):802)
classDescription_locked(objc_class*) (@classDescription_locked(objc_class*):83)
classDescription_locked(objc_class*) (@classDescription_locked(objc_class*):83)
classDescription(objc_class*) (@classDescription(objc_class*):64)
CA::Layer::class_state(objc_class*) (@CA::Layer::class_state(objc_class*):29)
-[CALayer init] (@-[CALayer init]:29)
+[CALayer layer] (@+[CALayer layer]:7)
-[NSView(NSPrivateLayerSupport) _createLayer] (@-[NSView(NSPrivateLayerSupport) _createLayer]:12)
-[NSView _createLayerAndInitialize] (@-[NSView _createLayerAndInitialize]:15)
-[NSView _updateLayerBackedness] (@-[NSView _updateLayerBackedness]:189)
-[NSView didChangeValueForKey:] (@-[NSView didChangeValueForKey:]:21)
-[NSTitlebarContainerView initWithFrame:] (@-[NSTitlebarContainerView initWithFrame:]:27)
__49-[NSThemeFrame _floatTitlebarAndToolbarFromInit:]_block_invoke (@__49-[NSThemeFrame _floatTitlebarAndToolbarFromInit:]_block_invoke:38)
+[NSAnimationContext runAnimationGroup:] (@+[NSAnimationContext runAnimationGroup:]:21)
-[NSThemeFrame _floatTitlebarAndToolbarFromInit:] (@-[NSThemeFrame _floatTitlebarAndToolbarFromInit:]:35)
-[NSThemeFrame initWithFrame:styleMask:owner:] (@-[NSThemeFrame initWithFrame:styleMask:owner:]:62)
-[NSWindow _commonInitFrame:styleMask:backing:defer:] (@-[NSWindow _commonInitFrame:styleMask:backing:defer:]:168)
-[NSWindow _initContent:styleMask:backing:defer:contentView:] (@-[NSWindow _initContent:styleMask:backing:defer:contentView:]:199)
-[NSWindow initWithContentRect:styleMask:backing:defer:] (@-[NSWindow initWithContentRect:styleMask:backing:defer:]:17)
-[NSWindow initWithContentRect:styleMask:backing:defer:screen:] (@-[NSWindow initWithContentRect:styleMask:backing:defer:screen:]:11)
Cocoa_CreateWindow (/Users/ryanjoseph/Developer/SDL2/src/video/cocoa/SDL_cocoawindow.m:1698)
SDL_CreateWindow_REAL (/Users/ryanjoseph/Developer/SDL2/src/video/SDL_video.c:1718)
SDL_CreateWindow (/Users/ryanjoseph/Developer/SDL2/src/dynapi/SDL_dynapi_procs.h:542)
::SETUPCANVAS(LONGINT, LONGINT, TEVENTCALLBACK, TCANVASOPTIONS) (/Users/ryanjoseph/Developer/Projects/FPC/GLCanvas/GLCanvas.pas:1441)
::PASCALMAIN() (/Users/ryanjoseph/Developer/Projects/FPC/MacOSGUI/tests/tgui4.pas:119)
FPC_SysEntry (@FPC_SysEntry:10)
FPC_SYSTEMMAIN (@FPC_SYSTEMMAIN:15)
main (@main:13)
start (@start:133)

This magically resolved itself in one project but happens in another and I can’t figure out why. For future reference here is an example program in Pascal that fails.

procedure TestSample; 
var
	flags: UInt32;
	window: PSDL_Window;
begin
	if SDL_Init(SDL_INIT_VIDEO) < 0 then
		halt(-1);

	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
			
	flags := SDL_WINDOW_SHOWN + SDL_WINDOW_OPENGL + SDL_WINDOW_RESIZABLE;
	window := SDL_CreateWindow('', SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 400, 400, flags);
end;