Repository navigation
libretro: wait for scheduler-safe state save and restore - #583
Merged
sonninnos merged 1 commit intoOct 9, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a fresh content load, restoring a Neo Geo savestate can return success and briefly display the saved scene, then reboot the emulated machine. This is reproducible with in-game Metal Slug 3 and 4 states; a successful unserialize return alone does not establish that the state resumed correctly.
Cause and change
MAME's
running_machine::handle_saveload()waits forscheduler.can_save()before both saving and loading, because pending anonymous timers can overwrite restored data. The libretro buffer entry points bypass this check.In the failing cold-load case, pending CPU input queues still have nonzero queue counts when scheduler postload removes their temporary delivery callbacks. Subsequent interrupts are not delivered correctly and the Neo Geo watchdog resets the machine. A debugger trace reaches
watchdog_timer_device::watchdog_expired()andschedule_soft_reset()after restoration.Wait for the same scheduler-safe condition before
write_buffer()andread_buffer(), advancing scheduler timeslices only while needed. Bound the wait to one emulated second and 100,000 iterations; return failure with a log message if it cannot become safe. The observed cold-load case needed one timeslice. This does not change the state format, disable the watchdog, or add an unconditional frame delay.This is independent of the session slot-default reset in #582, which is already in the base branch.
Reproduction
mslug3ormslug4, enter a level and save a state.Validation and limits
9069f39340f2d2b1795df8e71bb1d3d0fbc76598, with the libretro: reset machine options between content sessions #582 fix and this patch. This PR applies the same state change to current mastere858fcb097c59836f68a246648c4e0c070a8f083; it does not duplicate libretro: reset machine options between content sessions #582.mslug,mslug2,mslug3,mslug4,mslug5,mslugx,mslug3b6,sf2, andkof97; repeated 4-to-3 loading also passed. Some samples were credited player-selection screens, not in-level gameplay. SF2 was additionally continued for 1,500 frames.Build:
make -f Makefile.libretro platform=osx CROSS_COMPILE=1 LIBRETRO_APPLE_PLATFORM=arm64-apple-macos11 LIBRETRO_APPLE_ISYSROOT="$(xcrun --show-sdk-path)" -j10AI assistance
Diagnosis, implementation, and this description were assisted by OpenAI Codex (GPT-6 family; an exact model snapshot/version identifier is not exposed in this session). Validation above was executed locally, with the stated scope and limitations.