Skip to content

build: give the Windows main thread an 8 MiB stack (fixes #225)#227

Merged
LinuxJedi merged 1 commit into
LinuxJedi:mainfrom
hobbo91:fix/windows-main-thread-stack
Jul 19, 2026
Merged

build: give the Windows main thread an 8 MiB stack (fixes #225)#227
LinuxJedi merged 1 commit into
LinuxJedi:mainfrom
hobbo91:fix/windows-main-thread-stack

Conversation

@hobbo91

@hobbo91 hobbo91 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #225 — on Windows, clicking Run in the configuration screen crashes
the emulator with a silent exit (STATUS_STACK_OVERFLOW, 0xc00000fd). A
regression 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_runbuild_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:

  • Headless (--screenshot-after, unpaced) runs cleanly.
  • The same bundled-AROS machine booted directly (--config, paced + audio)
    runs cleanly — the machine and run loop are fine.
  • Only clicking Run — which builds deep inside the event-loop callback —
    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:8388608 for Windows-MSVC binary targets from build.rs, giving
the Windows main thread the same 8 MiB the other platforms already provide.
Target-gated via CARGO_CFG_TARGET_{OS,ENV} and scoped to binaries, so
Linux/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

  • Windows MSVC release build: the binary's PE SizeOfStackReserve is now 8 MiB
    (was 1 MiB), and clicking Run boots the machine instead of crashing.
  • Applies to both x86_64-pc-windows-msvc (the reporter's platform) and
    aarch64-pc-windows-msvc (where I verified). No effect on non-Windows targets.

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>
@hobbo91

hobbo91 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@LinuxJedi feel free to close this if you already had a PR ready to open

@LinuxJedi LinuxJedi left a comment

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.

We’ll go with your fix. It is almost identical. Many thanks for jumping on this.

@LinuxJedi
LinuxJedi merged commit e7c15d7 into LinuxJedi:main Jul 19, 2026
11 checks passed
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.

Copperline 0.12.0 Windows build doesn't work

2 participants