Skip to content

sim: Persist calculator state on exit#1689

Closed
alsrgv wants to merge 1 commit into
c3d:devfrom
alsrgv:persist-state-on-exit
Closed

sim: Persist calculator state on exit#1689
alsrgv wants to merge 1 commit into
c3d:devfrom
alsrgv:persist-state-on-exit

Conversation

@alsrgv
Copy link
Copy Markdown

@alsrgv alsrgv commented May 8, 2026

The simulator already saves its state on EXIT_PGM (see src/dmcp/main.cc), but only when a state-file path has previously been configured by the user via the SETUP > State > Save menu. On a fresh install the path is empty, so closing the window silently discards all settings (Beep mode, display options, etc.) and stack contents.

Default the persisted state-file path to "state/<PROGRAM_NAME>.48S" on first launch, so that exit reliably writes a state file and the next launch reliably restores it.

Also honor STATE_IO_SILENT in state_load_callback. With the default path set, the first launch (when no state file exists yet) was popping up a "State load failed: No such file or directory" dialog; silent loads should be silent on missing files too.

Copy link
Copy Markdown
Owner

@c3d c3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alsrgv, good idea, but a couple of suggestions.

Comment thread sim/sim-window.cpp
Comment thread sim/sim-window.cpp Outdated
// under the app data dir; QDir::setCurrent() is already pointed there.
{
char existing[256] = { 0 };
if (ui_read_setting("state", existing, sizeof(existing)) == 0)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (ui_read_setting("state", existing, sizeof(existing)) == 0)
if (ui_read_setting("state", nullptr, 0) == 0)

Comment thread sim/sim-window.cpp Outdated
// (it's a no-op when no path has been configured). The file lives
// under the app data dir; QDir::setCurrent() is already pointed there.
{
char existing[256] = { 0 };
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not necessary with the suggestion below, you don't care about the value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize value could be null - thanks for the feedback! Updated.

The simulator already saves its state on EXIT_PGM (see src/dmcp/main.cc),
but only when a state-file path has previously been configured by the
user via the SETUP > State > Save menu. On a fresh install the path is
empty, so closing the window silently discards all settings (Beep mode,
display options, etc.) and stack contents.

Default the persisted state-file path to "state/<PROGRAM_NAME>.48S" on
first launch, so that exit reliably writes a state file and the next
launch reliably restores it.

Also honor STATE_IO_SILENT in state_load_callback. With the default path
set, the first launch (when no state file exists yet) was popping up a
"State load failed: No such file or directory" dialog; silent loads
should be silent on missing files too.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Alex Sergeev <alexander.sergeev@live.com>
@alsrgv alsrgv force-pushed the persist-state-on-exit branch from 096d06c to 0142508 Compare May 8, 2026 21:08
@c3d c3d self-assigned this May 12, 2026
@c3d c3d added enhancement New feature or request simulator The problem is specific to the simulators done Issues that are done on dev (will be in next release) labels May 12, 2026
@c3d
Copy link
Copy Markdown
Owner

c3d commented May 12, 2026

Thanks @alsrgv, I pushed your fix on dev after adding you to the authors list. Welcome to the team 😉

@c3d c3d closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

done Issues that are done on dev (will be in next release) enhancement New feature or request simulator The problem is specific to the simulators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants