-
Notifications
You must be signed in to change notification settings - Fork 1
macOS crash on NSEventTypeFlagsChanged due to characters selector #2
Description
Summary
On macOS, Milky2018/window crashes when the backend receives an NSEventTypeFlagsChanged event, because mbw_content_view_flags_changed calls -[NSEvent characters] on that event.
This is reproducible downstream in Milky2018/mgstudio by running the examples/2d/sprite_flipping example on macOS native. The app aborts immediately with NSInternalInconsistencyException.
Current behavior
Current backend code in macos/backend.c:
mbw_content_view_flags_changed(...)- calls
mbw_event_nsstring_utf8(effective_event, "characters", ...) - also calls
charactersIgnoringModifiers
But AppKit raises on characters for FlagsChanged events:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid message sent to event "NSEvent: type=FlagsChanged ..."'
...
AppKit -[NSEvent characters]
libmacos.dylib mbw_content_view_flags_changed
Repro
- Run a native app using
Milky2018/windowon macOS. - Trigger or receive a modifier-state change event (
FlagsChanged). - The process aborts in
-[NSEvent characters].
In our downstream repo the repro command is:
moon run examples/2d/sprite_flippingRepo: https://github.com/moonbit-community/mgstudio-engine
Expected behavior
FlagsChanged should be handled without calling selectors that are invalid for that event type. Modifier transitions should emit key/modifier updates, but the app must not crash.
Suggested direction
Guard the text extraction path for FlagsChanged events. At minimum, avoid characters on this event kind and fall back to scancode/modifier-derived data instead. If text is still needed, only use selectors AppKit permits for this event type.
Notes
Current upstream main still contains this code path in macos/backend.c around mbw_content_view_flags_changed.