build: give the Windows main thread an 8 MiB stack (fixes #225)#227
Merged
Merged
Conversation
On Windows the main thread gets only ~1 MiB of stack, where Linux and macOS default to 8 MiB. The winit event loop runs on the main thread, and the configuration screen's Run boots the machine (launcher_run -> build_machine -> run_machine) from inside the event-loop callback -- so the machine build, the render-state rebuild, and the first present all run deep in the OS message-pump stack. That bounded work overflows 1 MiB (a silent STATUS_STACK_OVERFLOW when the user clicks Run) but fits comfortably in 8 MiB, so only Windows was affected, and only once the path's stack use grew past 1 MiB after 0.11. Emit /STACK:8388608 for Windows-MSVC binaries from build.rs, matching the 8 MiB the other platforms already give. Target-gated via CARGO_CFG_TARGET_* and scoped to bins, so non-Windows and library builds are unaffected. Fixes LinuxJedi#225. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
|
@LinuxJedi feel free to close this if you already had a PR ready to open |
LinuxJedi
approved these changes
Jul 19, 2026
LinuxJedi
left a comment
Owner
There was a problem hiding this comment.
We’ll go with your fix. It is almost identical. Many thanks for jumping on this.
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.
Summary
Fixes #225 — on Windows, clicking Run in the configuration screen crashes
the emulator with a silent exit (
STATUS_STACK_OVERFLOW,0xc00000fd). Aregression since 0.11.0; the GUI otherwise works for configuring and saving.
Root cause
Windows reserves only ~1 MiB of stack for the main thread; Linux and macOS
default to 8 MiB. The winit event loop must run on the main thread, and the
configuration screen's Run (
launcher_run→build_machine→run_machine) builds the machine, rebuilds the host render/presentation state,and does the first present from inside the event-loop callback — already
deep in the OS message-pump stack. That bounded-but-substantial work fits in
8 MiB but overflows 1 MiB. It crossed the 1 MiB line between 0.11 and 0.12,
which is why 0.11 was unaffected.
It reproduces only on the launcher Run path:
--screenshot-after, unpaced) runs cleanly.--config, paced + audio)runs cleanly — the machine and run loop are fine.
overflows.
size_of::<Emulator>()is ~48 KiB, so this is call-stack depth on that path,not a single oversized value on the stack.
Fix
Emit
/STACK:8388608for Windows-MSVC binary targets frombuild.rs, givingthe Windows main thread the same 8 MiB the other platforms already provide.
Target-gated via
CARGO_CFG_TARGET_{OS,ENV}and scoped to binaries, soLinux/macOS and library builds are untouched.
Matching the main-thread stack (rather than deferring the boot out of the
callback) is deliberate: the work is bounded and already known-good with an
8 MiB stack on the other two platforms, so this is the minimal change that
makes Windows behave the same.
Testing
SizeOfStackReserveis now 8 MiB(was 1 MiB), and clicking Run boots the machine instead of crashing.
x86_64-pc-windows-msvc(the reporter's platform) andaarch64-pc-windows-msvc(where I verified). No effect on non-Windows targets.