feat(minarch): undo load state - #792
Open
duonqfs wants to merge 2 commits into
Open
Conversation
Adds undo for an accidental load state, mirroring RetroArch's undo_load_state. Loading a state through the in-game menu or the Load State shortcut now snapshots the running state to memory first. Undoing swaps that snapshot with the current state, so pressing undo a second time returns to the state that was loaded — the same swap semantics RetroArch uses. Nothing is written to the SD card. Reachable two ways: an "Undo" row in the in-game menu, under Load, and a bindable "Undo Load State" shortcut. The menu row greys out via State_hasUndo() whenever no snapshot is available and does nothing when confirmed, so the menu never offers an action it can't perform. Availability is evaluated on menu redraw rather than every frame, keeping core.serialize_size() off the hot path. The snapshot is only kept when the load actually succeeded, and it is dropped if the core starts reporting a different serialize size. Disc changes drop it too: Menu_loadState() swaps discs before reading the state, so a snapshot taken afterwards would hold the previous disc's machine state while the new disc is inserted. A load that changed discs skips the capture entirely, and changing discs from the menu's Continue row invalidates a stale snapshot. Undo is blocked in RetroAchievements hardcore mode, same as loading a state.
Author
|
Hi @frysee , when you have a chance, could you please take a look at this PR? I'd really appreciate your review. Thanks! |
Member
|
I will, thanks. What I can already tell you is that this should not take up space in the main menu, imo. |
|
Could the Undo Load option be made to be one of the selectable loadable states (left/right when hovering over 'Load'?) I think that might be the ideal way to express this to the user via the UI without adding an extra top level menu entry. Of course this would also need frysee's approval, but just a thought. |
Author
duonqfs
force-pushed
the
feat/undo-load-state
branch
from
July 28, 2026 06:39
d17d0e8 to
5806ecc
Compare
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.

Adds undo for an accidental load state, mirroring RetroArch's undo_load_state.
Loading a state through the in-game menu or the Load State shortcut now snapshots the running state to memory first. Undoing swaps that snapshot with the current state, so pressing undo a second time returns to the state that was loaded — the same swap semantics RetroArch uses. Nothing is written to the SD card.
Reachable two ways: an "Undo" row in the in-game menu, under Load, and a bindable "Undo Load State" shortcut. The menu row greys out via State_hasUndo() whenever no snapshot is available and does nothing when confirmed, so the menu never offers an action it can't perform. Availability is evaluated on menu redraw rather than every frame, keeping core.serialize_size() off the hot path.
The snapshot is only kept when the load actually succeeded, and it is dropped if the core starts reporting a different serialize size. Disc changes drop it too: Menu_loadState() swaps discs before reading the state, so a snapshot taken afterwards would hold the previous disc's machine state while the new disc is inserted. A load that changed discs skips the capture entirely, and changing discs from the menu's Continue row invalidates a stale snapshot.
Undo is blocked in RetroAchievements hardcore mode, same as loading a state.


