Skip to content

Fix fatal JVM crash on macOS during hardware instancing (LwjglGLExt ARB extensions)#2893

Open
riccardobl with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-jvm-crash-macos-hardware-instancing
Open

Fix fatal JVM crash on macOS during hardware instancing (LwjglGLExt ARB extensions)#2893
riccardobl with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-jvm-crash-macos-hardware-instancing

Conversation

Copilot AI commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

On macOS, OpenGL Core Profile drivers strip legacy ARB extension function pointers even when equivalent functionality is available via core entry points. LwjglGLExt was unconditionally dispatching through ARB (e.g. ARBDrawInstanced.glDrawArraysInstancedARB), causing an immediate fatal native crash on any instanced draw call.

Changes

  • jme3-lwjgl3/LwjglGLExt.java: Each method now queries GL.getCapabilities() at runtime and dispatches to the core GL entry point when available, falling back to the ARB extension only for older contexts (e.g. GL 2.0 + ARB extensions) that predate the core promotion.
Method Core (preferred) Fallback
glDrawArraysInstancedARB GL31.glDrawArraysInstanced ARBDrawInstanced
glDrawElementsInstancedARB GL31.glDrawElementsInstanced ARBDrawInstanced
glVertexAttribDivisorARB GL33.glVertexAttribDivisor ARBInstancedArrays
glGetMultisample / glTexImage2DMultisample GL32.* ARBTextureMultisample
UBO methods GL30/GL31.* ARBUniformBufferObject
Sync methods GL32.* ARBSync
SSBO / program resource GL43.* ARBShaderStorageBufferObject / ARBProgramInterfaceQuery

Example dispatch pattern applied throughout:

@Override
public void glDrawArraysInstancedARB(int mode, int first, int count, int primCount) {
    if (GL.getCapabilities().OpenGL31) {
        GL31.glDrawArraysInstanced(mode, first, count, primCount);
    } else {
        ARBDrawInstanced.glDrawArraysInstancedARB(mode, first, count, primCount);
    }
}

…tead of ARB extensions

On macOS OpenGL Core Profile, legacy ARB extension pointers are stripped
even when the same functionality is available via core entry points. This
caused a JVM crash when attempting hardware instancing because
LwjglGLExt was calling ARBDrawInstanced/ARBInstancedArrays functions that
don't exist in the Core Profile.

Each method now prefers the equivalent core GL function (promoted to core
in the GL version noted in the comment) and falls back to the corresponding
ARB extension only when the core entry point is unavailable. This keeps
compatibility with older GL2-era contexts that have the ARB extensions
but lack the core promotion.

Affected mappings:
- glDrawArraysInstancedARB   → GL31.glDrawArraysInstanced (core since GL3.1)
- glDrawElementsInstancedARB → GL31.glDrawElementsInstanced (core since GL3.1)
- glVertexAttribDivisorARB   → GL33.glVertexAttribDivisor (core since GL3.3)
- glGetMultisample           → GL32.glGetMultisamplefv (core since GL3.2)
- glTexImage2DMultisample    → GL32.glTexImage2DMultisample (core since GL3.2)
- glGetUniformBlockIndex     → GL31.glGetUniformBlockIndex (core since GL3.1)
- glBindBufferBase           → GL30.glBindBufferBase (core since GL3.0)
- glUniformBlockBinding      → GL31.glUniformBlockBinding (core since GL3.1)
- glGetProgramResourceIndex  → GL43.glGetProgramResourceIndex (core since GL4.3)
- glShaderStorageBlockBinding→ GL43.glShaderStorageBlockBinding (core since GL4.3)
- glFenceSync                → GL32.glFenceSync (core since GL3.2)
- glClientWaitSync           → GL32.glClientWaitSync (core since GL3.2)
- glDeleteSync               → GL32.glDeleteSync (core since GL3.2)

Fixes #2892
Copilot AI changed the title [WIP] Fix fatal JVM crash on macOS during hardware instancing Fix fatal JVM crash on macOS during hardware instancing (LwjglGLExt ARB extensions) Jul 5, 2026
Copilot AI requested a review from riccardobl July 5, 2026 12:47
@riccardobl riccardobl marked this pull request as ready for review July 5, 2026 13:55
@riccardobl riccardobl requested a review from Copilot July 5, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the LWJGL3 GLExt implementation to avoid native JVM crashes on macOS Core Profile by preferring core OpenGL entry points (when available) instead of dispatching through legacy ARB extension function pointers that may be stripped by the driver.

Changes:

  • Switch instancing calls (glDraw*Instanced*, glVertexAttribDivisor*) to dispatch to core GL methods when the corresponding core version is available, otherwise fall back to ARB extensions.
  • Apply the same core-preferred dispatch pattern to multisample texture functions, UBO-related functions, sync objects, and several newer-program-interface/SSBO-related functions.
  • Improve class-level Javadoc (including a typo fix and explanation of the macOS Core Profile issue).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Fatal JVM crash on macOS during Hardware Instancing (LwjglGLExt hardcoded to ARB extensions)

3 participants