Fix craft run stack overflow on Windows by using direct lookup#32
Open
DaanyaalSobani wants to merge 1 commit into
Open
Fix craft run stack overflow on Windows by using direct lookup#32DaanyaalSobani wants to merge 1 commit into
craft run stack overflow on Windows by using direct lookup#32DaanyaalSobani wants to merge 1 commit into
Conversation
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]>
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.
Fixes #31.
What
run.cno longer callssearch_dir_for_fileto 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_filerecurses through every subdirectory ofbuild/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 reachingbuild/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:
craft project repro_app --lang ccraft buildcraft run0xC00000FD/0xC00000050Tested 5× in succession — all clean exits.
Notes
search_dir_for_fileis untouched in this PR. After this change it has no remaining callers; happy to remove it (or harden itssub_dirsallocation) as a follow-up if you'd prefer.{"", "Debug", "Release", "MinSizeRel", "RelWithDebInfo"}covers the standard CMake build types. Custom configurations would fall through to the existing "not found" error — same as before.