Skip to content

Ensure GL device objects before renderDrawData after 1.86→1.87 upgrade - #423

Merged
SpaiR merged 1 commit into
SpaiR:mainfrom
arimu1:fix/361-gl3-device-objects-before-render
Aug 1, 2026
Merged

Ensure GL device objects before renderDrawData after 1.86→1.87 upgrade#423
SpaiR merged 1 commit into
SpaiR:mainfrom
arimu1:fix/361-gl3-device-objects-before-render

Conversation

@arimu1

@arimu1 arimu1 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Since imgui-java 1.87, ImGuiImplGl3 creates the shader/program/VBO and font texture lazily in newFrame() (not in init()), matching upstream imgui_impl_opengl3. Integrators that still use the pre-1.87 pattern of init() + renderDrawData() without newFrame() then crash in native code (glDrawElementsBaseVertex NULL dereference / EXCEPTION_ACCESS_VIOLATION).

This change reuses that lazy create path from renderDrawData() as a safety net, so the upgrade path reported in #361 no longer hard-crashes the JVM. Calling newFrame() every frame remains the recommended API.

Type of change

  • Minor changes or tweaks (quality of life stuff)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Notes for reviewer

  • Root cause of Bug: An "null pointer" error occurred. #361: device objects never created when newFrame() is skipped; shaderHandle / buffer handles stay 0 and the draw call faults in the GL driver.
  • The issue author later worked around it by calling imGuiGl3.newFrame() during init (see their jME hub write-up and @Enaium's comment). This patch keeps that recommendation and additionally makes renderDrawData() self-sufficient for the upgrade path.
  • No new public API beyond a small protected ensureDeviceObjects() helper shared by newFrame() / renderDrawData().
  • Javadoc on init / newFrame updated to document the post-1.87 lazy create.

Fixes #361

Test plan

  • ./gradlew :imgui-lwjgl3:compileJava :imgui-lwjgl3:checkstyleMain (JDK 17)
  • No automated GL unit test exists for this path; visual smoke would be ./gradlew :example:run with local natives if desired

Since 1.87, ImGuiImplGl3 creates the shader/program/VBO and font texture
lazily in newFrame() rather than in init(), matching upstream. Call sites
that only call init() + renderDrawData() (the pre-1.87 pattern used by
many jME / custom loops) then hit a native NULL dereference inside
glDrawElementsBaseVertex.

Share the lazy create path with renderDrawData so those upgrades no
longer crash. Prefer calling newFrame() every frame; this is a safety
net for the upgrade path reported in SpaiR#361.

Fixes SpaiR#361
@SpaiR SpaiR added the fix Fixes problems label Jul 31, 2026
@SpaiR
SpaiR merged commit 9a26851 into SpaiR:main Aug 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Fixes problems

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: An "null pointer" error occurred.

2 participants