Skip to content

libretro: reset machine options between content sessions - #582

Merged
sonninnos merged 1 commit into
libretro:masterfrom
BigBossWHD:fix/libretro-reset-machine-options
Oct 8, 2026
Merged

sonninnos merged 1 commit into
libretro:masterfrom
BigBossWHD:fix/libretro-reset-machine-options

Conversation

@BigBossWHD

Copy link
Copy Markdown

Loading another Neo Geo game without unloading the core library can retain the previous cartridge type. For example, mslug3 -> mslug4 starts the latter with :cslot1:sma_mslug3 instead of :cslot1:pcm2_mslug4, producing the BIOS crosshatch screen. Loading kof97 after mslug4 can likewise retain the PCM2 cartridge and crash. A fresh process boots these games normally.

Cause and change

mmain() retains a static retro_options across sessions. When the next machine has a slot with the same name, emu_options::add_and_remove_slot_options() keeps the existing slot option and its old default. Changing the system directly therefore does not necessarily replace the cartridge type.

Reset the system name to an empty string before starting the next frontend session. The existing empty-system path removes obsolete slot/image options, allowing the next machine to populate its own defaults. This keeps the options object's required lifetime and does not special-case particular games or modify the general MAME options implementation.

Reproduction

  1. Start mslug3 with the MAME core.
  2. Close content, then load mslug4 in the same RetroArch process.
  3. Observe the crosshatch screen and the stale sma_mslug3 cartridge in verbose output. Cold-starting mslug4 selects pcm2_mslug4 instead.
  4. Another affected sequence is mslug4 -> kof97, which can crash with the previous cartridge type still selected.

This was also reproduced outside RetroArch in a small libretro host retaining the same loaded library while cycling retro_init / retro_load_game / retro_run / retro_unload_game / retro_deinit. The reproducer used isolated save directories, no input, no savestates, and disabled threaded mode, so automatic state loading and RetroArch frontend state are not required triggers.

Validation

Tested against 9069f39340f2d2b1795df8e71bb1d3d0fbc76598 (MAME 0.289) on macOS ARM64:

  • Full libretro core build succeeded.
  • The failing mslug3 -> mslug4 and mslug4 -> kof97 cases select the correct cartridge and run after the change.
  • Mixed sequences covering Neo Geo, CPS1, and IGS PGM passed.
  • 76 arcade titles passed sequential load/run (900 frames)/unload smoke checks in two sequences with threaded mode enabled. One additional title with independently confirmed missing ROM components was excluded. These are startup/teardown checks, not full gameplay or exhaustive pairwise coverage.
  • mslug3, mslug4, sf2ce, kof97, and kov passed save, unload, intervening content loads, reload, unserialize, and continued execution with threaded mode enabled.
  • RetroArch 1.22.2 separately saved an automatic state for mslug4, exited, and successfully loaded it on the next launch using isolated directories.

Build command:

make -f Makefile.libretro platform=osx CROSS_COMPILE=1 \
  LIBRETRO_APPLE_PLATFORM=arm64-apple-macos11 \
  LIBRETRO_APPLE_ISYSROOT="$(xcrun --show-sdk-path)" -j10

Windows, Linux, and non-arcade machine/softlist configurations have not been runtime-tested.

AI assistance

This diagnosis, patch, and description were prepared with OpenAI Codex (GPT-6). The exact serving snapshot identifier is not exposed in this session. The validation above was executed locally; its platform and coverage limits are stated explicitly.

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