Skip to content

macOS: fix crash on document open with sdl2-compat - #2500

Merged
flyinghead merged 1 commit into
flyinghead:masterfrom
richstokes:macos-open-file-user-event
Sep 20, 2026
Merged

flyinghead merged 1 commit into
flyinghead:masterfrom
richstokes:macos-open-file-user-event

Conversation

@richstokes

Copy link
Copy Markdown
Contributor

Follow-up to #2492. When Flycast is built against Homebrew's sdl2, which is now sdl2-compat on top of SDL3, launching with a game on the command line segfaults during window creation:

SDL_strdup_REAL
Event3to2                      (libSDL2-2.0.0.dylib, sdl2-compat)
EventFilterWrapper3to2
SDL_FilterEvents_REAL
...
SDL_CreateWindow_REAL
sdl_recreate_window(unsigned int)   sdl.cpp

AppKit also delivers the command-line game through application:openFile:, which pushes an SDL_DROPFILE event. sdl2-compat's Event2to3() has no case for drop events, so the SDL2 drop.file pointer doesn't end up in SDL3's drop.data. When the queued event is later converted back, Event3to2() calls SDL_strdup(event3->drop.data) with NULL. Official builds bundle real SDL2, so they aren't affected.

This keeps the design from #2492 (the document waits in SDL's event queue until the main loop is running, without setting commandLineStart) but carries the path in an event type from SDL_RegisterEvents(). User events keep the same layout in both SDL versions, so data1 survives the round trip. The queueing moves into sdl_queue_open_file() in core/sdl/sdl.cpp next to the handler that frees the string.

Tested on Apple Silicon, macOS 27, native CMake build of this branch:

SDL game on command line open -a Flycast.app game.elf
Homebrew sdl2-compat 2.32.72 / SDL 3.4.16 boots (crashed before) boots
bundled SDL2 boots boots

sdl2-compat (what Homebrew installs as sdl2) doesn't convert the file
name of an SDL_DROPFILE event pushed by the application, then crashes
in strdup(NULL) when converting the event back during window creation.
Carry the path in a registered user event instead.
@flyinghead
flyinghead merged commit 628bd3d into flyinghead:master Sep 20, 2026
19 checks passed
richstokes added a commit to richstokes/dreamcast-homebrew that referenced this pull request Sep 21, 2026
flyinghead/flycast#2500 is merged, so the bundled-SDL detour and its
Objective-C build patch hunk are no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants