Skip to content

Fix macOS SDL and OpenGL startup - #65

Open
wmill wants to merge 2 commits into
afwbkbc:mainfrom
wmill:macos-apple-silicon-fixes
Open

wmill wants to merge 2 commits into
afwbkbc:mainfrom
wmill:macos-apple-silicon-fixes

Conversation

@wmill

@wmill wmill commented Aug 23, 2026

Copy link
Copy Markdown

Summary

  • Run the engine's existing logical t_main directly on the macOS process main thread, so SDL/Cocoa window and event handling, audio initialization, and OpenGL all remain on the thread expected by AppKit.
  • Request an Apple OpenGL core context before window creation, enable GLEW core entry points, and keep one VAO bound for the lifetime of the context.
  • Handle Apple core-profile initialization errors without changing Linux or Windows OpenGL behavior.
  • Stop the inline main loop cleanly on macOS and use safe reverse module teardown on that platform.
  • Call SDL_SetMainReady() for the existing SDL_MAIN_HANDLED entry point on macOS.

Approach

This follows the direction suggested in #58: the existing t_main becomes the actual OS main thread on Apple. It avoids a separate dispatch queue, per-frame OpenGL context transfers, synchronous swap dispatch, and temporary per-draw VAOs.

All changed runtime behavior is guarded by __APPLE__. Non-Apple builds retain their existing thread startup, shutdown signaling, OpenGL attribute timing, swap timing, GLEW behavior, VAO behavior, and legacy OpenGL hint.

Testing

Tested on macOS 26.3, arm64, Apple M4 Pro:

  • Debug CMake build with Homebrew dependencies succeeds.
  • SDL creates the window on the process main thread.
  • Apple reports OpenGL 4.1 / GLSL 4.10 and both shader programs initialize.
  • Original SMAC/Alien Crossfire assets load successfully.
  • A generated game ran through multiple turns and map resets.
  • Built-in GSE test suite completes with All tests passed.
  • Clean window shutdown completes without reported memory or OpenGL leaks.

Linux and Windows were not available for runtime testing; their existing code paths are preserved with compile-time Apple guards.

Related

This is a current-main, narrowly scoped alternative to #58. It deliberately excludes that PR's unrelated interpreter, logging, unit-manager, crash-handler, path-resolution, and editor/build changes.

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.

1 participant