Skip to content

fix Linux segfault from stale JAWT drawable on OpenGL backend#766

Closed
jamesarich wants to merge 1 commit into
maplibre:mainfrom
jamesarich:fix/desktop-linux-segfault
Closed

fix Linux segfault from stale JAWT drawable on OpenGL backend#766
jamesarich wants to merge 1 commit into
maplibre:mainfrom
jamesarich:fix/desktop-linux-segfault

Conversation

@jamesarich
Copy link
Copy Markdown

Fixes #564

The segfault inside render() was caused by incorrect JAWT usage: Display* and Drawable were captured once in JawtContext's constructor and cached forever. The JAWT spec requires re-fetching surface info after every Lock() call — the X11 Drawable (window ID) changes when the AWT peer is recreated on first show, on resize, or when JAWT_LOCK_SURFACE_CHANGED is returned. Passing a stale Drawable to glXMakeCurrent/glXSwapBuffers is what causes the crash.

Raised as one of the items in @sargunv's comment at sargunv/maplibre-native#2 (comment).

Changes

  • jawt_context.hpplock() now calls GetDrawingSurfaceInfo() after each Lock() and refreshes platform surface info (display, drawable, etc.); unlock() calls FreeDrawingSurfaceInfo() before Unlock(), following the required JAWT lifecycle. Constructor simplified to a single lock/unlock to initialise the Display* (which is the JVM's persistent X11 connection and never changes).
  • canvas_opengl_backend.cpp — destructor: replace check() (throws from a destructor → UB during stack unwinding) with an early-return guard; use glXMakeCurrent(display, None, nullptr) to release the context without needing a valid window; activate() checks the glXMakeCurrent return value and throws a descriptive error on failure rather than silently proceeding with no current context; deactivate() also uses None as the drawable when releasing, for consistency.
  • canvas_frontend.cpp — remove the TODO comment that flagged the segfault.

Checklist

To your knowledge, are you making any breaking changes? No.

Have you tested the changes? On which platforms?

  • macOS: builds and runs cleanly; cannot reproduce the Linux segfault on macOS but the fix is deterministic from the JAWT spec.

@sargunv
Copy link
Copy Markdown
Collaborator

sargunv commented Apr 18, 2026

I've also prompted AI to help investigate this, and it loves to flag this, but the segfault persists on Linux. This bug requires some deeper exploration (and actual testing on a Linux machine)

@sargunv sargunv closed this Apr 18, 2026
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.

SIGSEGV on Linux

2 participants