Skip to content

Secondary threads on Apple platforms are more susceptible to stack overflow than on other platforms #112093

@mihe

Description

@mihe

Tested versions

  • Reproducible in: 4.6.dev [0fdb93c]

System information

Godot v4.6.dev (0fdb93c) - macOS Tahoe (26.0.1) - Multi-window, 1 monitor - Metal (Forward+) - integrated Apple M2 Pro (Apple8) - Apple M2 Pro (10 threads) - 32.00 GiB memory

Issue description

Apple platforms (e.g. macOS, iOS) use a default stack size of 512 KiB for secondary threads. This is unlike most other platforms where it instead is at least 1 MiB.

We currently increase the stack size for WorkerThreadPool threads specifically on Apple platforms, in order to not run into stack overflows as a result of SPIRV-Cross, as seen here:

Thread::Settings settings;
#ifdef __APPLE__
// The default stack size for new threads on Apple platforms is 512KiB.
// This is insufficient when using a library like SPIRV-Cross,
// which can generate deep stacks and result in a stack overflow.
#ifdef DEV_ENABLED
// Debug builds need an even larger stack size.
settings.stack_size = 2 * 1024 * 1024; // 2 MiB
#else
settings.stack_size = 1 * 1024 * 1024; // 1 MiB
#endif
#endif

This however does nothing to resolve the problem for threads spawned from scripts (i.e. Thread), where you're still more likely to run into a stack overflow on Apple platforms.

Steps to reproduce

  1. Build a non-optimized editor build for macOS (i.e. target=editor dev_build=yes).
  2. Run the main scene in the MRP.
  3. Note the crash.
  4. Build a non-optimized editor build for Windows or Linux.
  5. Run the main scene again.
  6. Note how there's no crash.

Minimal reproduction project (MRP)

apple-stack-overflow.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions