Skip to content

G4OSG viewer: render in the main thread on macOS (fixes SIGILL crash) - #60

Merged
tkittel merged 1 commit into
mctools:mainfrom
MilanKlausz:macos-viewer-main-thread
Nov 7, 2026
Merged

tkittel merged 1 commit into
mctools:mainfrom
MilanKlausz:macos-viewer-main-thread

Conversation

@MilanKlausz

Copy link
Copy Markdown
Contributor

On macOS the G4OSG viewer (--viewer) crashes with Illegal instruction: 4 (SIGILL). It happens after the
window has been resized (F/F5 fullscreen toggle, resizing by hand, or the window being brought to the front),
as soon as osgViewer restarts its draw thread, e.g. when the axes are toggled (CTRL-A) or the hover text
changes.

The crash report always has the same stack in the draw thread:

AppKit                    -[NSOpenGLContext update]
libosgViewer.3.6.5.dylib  osgViewer::GraphicsWindowCocoa::makeCurrentImplementation()
libosg.3.6.5.dylib        osg::GraphicsContext::makeCurrent()
libosg.3.6.5.dylib        osg::GraphicsThread::run()
libOpenThreads.3.3.1.dylib OpenThreads::ThreadPrivateActions::StartThread(void*)

with the message -[NSOpenGLContext update] must be called from the main thread if the context has a view.
After a resize, GraphicsWindowCocoa calls [NSOpenGLContext update] in the next makeCurrent, and AppKit
only allows that on the main thread.

The fix: on macOS (#ifdef __APPLE__) the viewer uses osgViewer's SingleThreaded threading model, so all
rendering is in the main thread. Other platforms are unchanged.

Tested on macOS 26 (Apple silicon), simple-build-dgcode 2.0.1 from conda-forge, OpenSceneGraph 3.6.5,
Geant4 11.4.3:

  • unpatched 2.0.1 viewer: the crash above, reproduced again with 2.0.1 (also seen many times with 1.x);
  • patched viewer (the same change in a local copy of G4OSG, in use since 2026-10-29): no crash.

🤖 Generated with Claude Code

After a window resize (or the window being brought to the front),
osgViewer's GraphicsWindowCocoa calls [NSOpenGLContext update] in the next
makeCurrent. AppKit only allows that on the main thread, so the draw thread
of the default threading model, (re)started by startThreading() (e.g. when
the axes or the hover text change), dies with SIGILL (Illegal instruction: 4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tkittel
tkittel merged commit 0e81727 into mctools:main Nov 7, 2026
23 of 30 checks passed
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