Skip to content

Fixed three macOS bugs (save-state crash, blank Input settings, ROM double-click) - #3

Open
mysterypaintwo wants to merge 5 commits into
alttpo:unstablefrom
mysterypaintwo:unstable
Open

Fixed three macOS bugs (save-state crash, blank Input settings, ROM double-click)#3
mysterypaintwo wants to merge 5 commits into
alttpo:unstablefrom
mysterypaintwo:unstable

Conversation

@mysterypaintwo

Copy link
Copy Markdown

This PR fixes three unrelated bugs, all reproduced and verified on Apple Silicon (macOS 26 Tahoe). None of the changes affect SNES emulation (sfc/, processor/); they are limited to save-state I/O, UI, and macOS integration.

  1. Fix save-state load crash (heap corruption).
    nall::Decode::RLE reconstructed the uncompressed size using undefined behavior (shifting a promoted 32-bit value by up to 56 bits), producing an invalid allocation size on arm64. This corrupted the heap during decompression and caused a crash shortly afterward. The decoder now matches the encoder's 64-bit implementation.

  2. Fix empty Input/Hotkeys mapping list on first open.
    SettingsWindow::show() activated the window through the base Window class, bypassing SettingsWindow::setVisible(), which refreshes the mapping list. As a result, mappings only appeared after changing the device dropdown. The mappings are now refreshed whenever the window is shown.

  3. Fix opening ROMs via Finder ("Open With" / double-click).
    bsnes previously had no document-opening path on macOS because Info.plist did not declare supported document types and no Apple Event handler was registered. This PR:

    • registers a kAEOpenDocuments handler early in startup,
    • buffers open requests until the application is ready, and
    • adds document type declarations for supported ROM formats (.sfc, .smc, .gb, .gbc, .bs, .st) using LSHandlerRank: Alternate.

    During testing I also found duplicate LaunchServices registrations can prevent file opening on some development systems. That's an environment issue rather than a code bug, but reviewers who can't reproduce may want to clear stale registrations with lsregister.

Testing

Verified manually on Apple Silicon (macOS 26 Tahoe):

  • Save-state load no longer crashes.
  • Settings -> Input/Hotkeys populates mappings immediately on first open.
  • Opening a ROM via Finder (open -a bsnes.app romfile.sfc) with no bsnes process running beforehand (confirmed via ps) successfully launches the emulator and loads the ROM. This distinction matters: an already-running instance receives document-open events through a different path and would pass even without this fix, so this was specifically tested as a cold launch.
  • Loaded the alttpo AngelScript script folder with no errors, confirming AngelScript's arm64 support (already present on this branch's unstable base) works correctly alongside these fixes.

@mysterypaintwo
mysterypaintwo changed the base branch from stable to unstable July 25, 2026 05:28
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.

1 participant