Skip to content

fix: compile with exceptions disabled in dispatch_queue - #243

Merged
parkergrt merged 1 commit into
pixpark:mainfrom
avosa:fix/build-without-exceptions
Aug 27, 2026
Merged

parkergrt merged 1 commit into
pixpark:mainfrom
avosa:fix/build-without-exceptions

Conversation

@avosa

@avosa avosa commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Building an app that consumes gpupixel with -fno-exceptions currently fails: DispatchQueue::runTask in src/utils/dispatch_queue.cc wraps the queued task in an unconditional try/catch, and the compiler rejects try when exceptions are disabled. This is the only exception handling site in the library, so this one file blocks the whole build for such apps.

This change guards the try/catch with #if defined(__cpp_exceptions) || defined(_CPPUNWIND). When exceptions are disabled, the fallback simply runs the task and fulfills the promise, which is safe because no exception can be in flight in that mode. Behavior with exceptions enabled is unchanged.

On the macro choice: __cpp_exceptions is used instead of __EXCEPTIONS because on Apple platforms the library sources are compiled as Objective-C++, where clang still defines __EXCEPTIONS (for ObjC exceptions) even under -fno-exceptions. __cpp_exceptions tracks C++ exceptions exactly on clang and gcc, and _CPPUNWIND covers MSVC.

Verified on macOS (arm64, Release):

  • ./script/build_macos.sh with default flags builds as before, and the preprocessor keeps the existing try/catch path.
  • A second configure with -DCMAKE_CXX_FLAGS=-fno-exceptions now builds the gpupixel target cleanly; on current main it fails in dispatch_queue.cc.
  • The file also compiles standalone as both C++ and Objective-C++, with and without -fno-exceptions.

DispatchQueue::runTask wraps tasks in an unconditional try/catch, which breaks the build when the embedding app compiles with -fno-exceptions. Guard it on __cpp_exceptions (clang/gcc) and _CPPUNWIND (MSVC); without exceptions the wrapped task just runs and fulfills the promise, since nothing can throw. Behavior with exceptions enabled is unchanged.
@parkergrt
parkergrt merged commit 5e4d71c into pixpark:main Aug 27, 2026
5 checks passed
@avosa
avosa deleted the fix/build-without-exceptions branch August 27, 2026 15:11
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.

2 participants