Skip to content

Fix craft run stack overflow on Windows by using direct lookup#32

Open
DaanyaalSobani wants to merge 1 commit into
randerson112:mainfrom
DaanyaalSobani:fix/windows-run-crash
Open

Fix craft run stack overflow on Windows by using direct lookup#32
DaanyaalSobani wants to merge 1 commit into
randerson112:mainfrom
DaanyaalSobani:fix/windows-run-crash

Conversation

@DaanyaalSobani

Copy link
Copy Markdown

Fixes #31.

What

run.c no longer calls search_dir_for_file to locate the project executable. Instead it tries the known CMake generator output locations directly:

  • build/<name> — single-config generators (Make, Ninja)
  • build/{Debug,Release,MinSizeRel,RelWithDebInfo}/<name> — multi-config generators (Visual Studio, Xcode)

Why

search_dir_for_file recurses through every subdirectory of build/ looking for <name>.exe. On Windows with CMake's Visual Studio generator (the default when MSVC is installed), build/CMakeFiles/ is 6+ levels deep, and each recursive call puts a 128 KB local array (char sub_dirs[128][PATH_SIZE]) on the stack. With Windows' default 1 MB thread stack, the recursion exhausts the stack before ever reaching build/Debug/<name>.exe.

See #31 for the full reproduction recipe, stack-frame math, and exception-code analysis.

Testing

Reproduction from #31, before and after this PR:

Step Before After
craft project repro_app --lang c works works
craft build works works
craft run silent crash, exit 0xC00000FD / 0xC0000005 prints "Hello, World!", exit 0

Tested 5× in succession — all clean exits.

Notes

  • search_dir_for_file is untouched in this PR. After this change it has no remaining callers; happy to remove it (or harden its sub_dirs allocation) as a follow-up if you'd prefer.
  • The candidate list {"", "Debug", "Release", "MinSizeRel", "RelWithDebInfo"} covers the standard CMake build types. Custom configurations would fall through to the existing "not found" error — same as before.

search_dir_for_file recursively walks the build directory looking
for <name>.exe. Each call puts a 128 KB array on the stack, and
CMake's Visual Studio generator nests build/CMakeFiles/ 6+ levels
deep — enough to exhaust Windows' 1 MB thread stack.

Look up the executable at the known CMake output locations instead:
build/<name> (single-config: Make, Ninja) and build/<config>/<name>
(multi-config: Visual Studio, Xcode). Constant-time lookup, no
recursion, no walk through CMakeFiles.

Fixes randerson112#31.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.

craft run silently crashes on Windows (stack overflow in search_dir_for_file)

1 participant