Repository: libsdl-org/SDL

Issue #5664: MACOSX: Crash in SDL_RecreateWindow() with latest head source
Created: 2022-05-16T07:17:38Z
Have a window with SDL_WINDOW_OPENGL and SDL_WINDOW_RESIZABLE flags.
Then create a SDL_Renderer, which picks the METAL Backend.
It now crashes after calling SDL_RecreateWindow (?):
#0	0x00007ff81173803f in objc_release ()
#1	0x0000000107d2ded9 in -[SDL_WindowData .cxx_destruct] at /Users/s/release/Release_SDL/SDL_git/src/video/cocoa/SDL_cocoawindow.m:65
#2	0x00007ff81173faae in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#3	0x00007ff811738183 in objc_destructInstance ()
#4	0x00007ff811738123 in _objc_rootDealloc ()
#5	0x0000000107d34297 in -[Cocoa_WindowListener .cxx_destruct] at /Users/s/release/Release_SDL/SDL_git/src/video/cocoa/SDL_cocoawindow.m:455
#6	0x00007ff81173faae in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#7	0x00007ff811738183 in objc_destructInstance ()
#8	0x00007ff811738123 in _objc_rootDealloc ()
#9	0x00007ff8143db974 in -[NSResponder dealloc] ()
#10	0x00007ff81173c14a in AutoreleasePoolPage::releaseUntil(objc_object**) ()
#11	0x00007ff811738f8f in objc_autoreleasePoolPop ()
#12	0x0000000107d35b5d in Cocoa_DestroyWindow at /Users/s/release/Release_SDL/SDL_git/src/video/cocoa/SDL_cocoawindow.m:2307
#13	0x0000000107c48286 in SDL_RecreateWindow at /Users/s/release/Release_SDL/SDL_git/src/video/SDL_video.c:1803
#14	0x0000000107d3905c in METAL_CreateRenderer at /Users/s/release/Release_SDL/SDL_git/src/render/metal/SDL_render_metal.m:1621
#15	0x0000000107b70261 in SDL_CreateRenderer_REAL at /Users/s/release/Release_SDL/SDL_git/src/render/SDL_render.c:977
#16	0x0000000107b3daf5 in SDL_CreateRenderer at /Users/s/release/Release_SDL/SDL_git/src/dynapi/SDL_dynapi_procs.h:332

Duplicate issue #5668: macOS: Crash on exit in latest code...
Created: 2022-05-16T17:38:19Z
I'm assuming this is a small thing that needs to be shaken out after we switched to requiring ARC, but I'm getting this crash on an M1 Mac Mini. Just run testsprite2 and hit Apple-Q to quit (or click the red "close" button on the titlebar, which gives a similar callstack)...
Process 69031 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100359e0)
    frame #0: 0x0000000196a32980 libobjc.A.dylib`objc_release + 16
libobjc.A.dylib`objc_release:
->  0x196a32980 <+16>: ldr    x10, [x9, #0x20]
    0x196a32984 <+20>: tbz    w10, #0x2, 0x196a329e4    ; <+116>
    0x196a32988 <+24>: tbz    w8, #0x0, 0x196a32a04     ; <+148>
    0x196a3298c <+28>: mov    x9, #0x100000000000000
Target 0: (testsprite2) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100359e0)
  * frame #0: 0x0000000196a32980 libobjc.A.dylib`objc_release + 16
    frame #1: 0x00000001005e5b68 libSDL2-2.0.0.dylib`-[SDL_WindowData .cxx_destruct](self=0x000060000211ecb0, _cmd=".cxx_destruct") at SDL_cocoawindow.m:65:17
    frame #2: 0x0000000196a3b914 libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 116
    frame #3: 0x0000000196a32adc libobjc.A.dylib`objc_destructInstance + 80
    frame #4: 0x0000000196a32a7c libobjc.A.dylib`_objc_rootDealloc + 80
    frame #5: 0x00000001005ebc40 libSDL2-2.0.0.dylib`-[Cocoa_WindowListener .cxx_destruct](self=0x000060000211ed50, _cmd=".cxx_destruct") at SDL_cocoawindow.m:455:17
    frame #6: 0x0000000196a3b914 libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 116
    frame #7: 0x0000000196a32adc libobjc.A.dylib`objc_destructInstance + 80
    frame #8: 0x0000000196a32a7c libobjc.A.dylib`_objc_rootDealloc + 80
    frame #9: 0x0000000199823fa8 AppKit`-[NSResponder dealloc] + 172
    frame #10: 0x0000000196a372c4 libobjc.A.dylib`AutoreleasePoolPage::releaseUntil(objc_object**) + 196
    frame #11: 0x0000000196a33b04 libobjc.A.dylib`objc_autoreleasePoolPop + 212
    frame #12: 0x00000001005ed154 libSDL2-2.0.0.dylib`Cocoa_DestroyWindow(_this=0x000000010401c000, window=0x0000600003d00000) at SDL_cocoawindow.m:2307:1
    frame #13: 0x00000001005bf5cc libSDL2-2.0.0.dylib`SDL_DestroyWindow_REAL(window=0x0000600003d00000) at SDL_video.c:3160:9
    frame #14: 0x00000001005bbf94 libSDL2-2.0.0.dylib`SDL_VideoQuit_REAL at SDL_video.c:3260:9
    frame #15: 0x00000001004b22b4 libSDL2-2.0.0.dylib`SDL_VideoQuit at SDL_dynapi_procs.h:528:1
    frame #16: 0x00000001000099cc testsprite2`SDLTest_CommonQuit(state=0x0000000100304df0) at SDL_test_common.c:2226:9
    frame #17: 0x000000010000380c testsprite2`quit(rc=0) at testsprite2.c:58:5
    frame #18: 0x00000001000037b4 testsprite2`main(argc=1, argv=0x000000016fdff7b0) at testsprite2.c:581:5
    frame #19: 0x0000000100025088 dyld`start + 516

...an autorelease after ARC already released it, maybe?
Assigning to myself, but pinging @slime73 in case it's a quick fix.

Closing comment (2022-05-16T18:29:13Z): Closing this as a duplicate of #5664.