SpaiR / imgui-java

JNI based binding for Dear ImGui
MIT License
587 stars 90 forks source link

Bug: JVM Crash #178

Closed ryanftpsh closed 1 year ago

ryanftpsh commented 1 year ago

Version

Latest

What happened?

This is my code: `public class ImGuiScreen extends GuiScreen { private static ImGui imgui = new ImGui();

private static ImGuiImplGl3 implGl3;
private static ImGuiImplGlfw implGlfw;
private static ImGuiIO io;
private static ImGuiContext ctx;

private float[] f = {0f};
private float[] clearColor = {0.45f, 0.55f, 0.6f, 1f};
private boolean showDemo = true;
private boolean showAnotherWindow = false;
private int[] counter = {0};

static {
    long handle = Minecraft.getMinecraft().handle;
    GLFW.glfwMakeContextCurrent(handle);
    ctx = new ImGuiContext(handle);
    implGlfw = new ImGuiImplGlfw();
    implGlfw.init(handle, false);
    implGl3 = new ImGuiImplGl3();

    io = imgui.getIO();
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    implGlfw.newFrame();
    imgui.newFrame();

    imgui.text("Hello Minecraft!");
    imgui.sliderFloat("float", f, 0f, 1f, "%.3f", 1);
    imgui.colorEdit3("clear color", clearColor, 0);

    imgui.checkbox("Demo Window", showDemo);
    imgui.checkbox("Another Window", showAnotherWindow);

    if (imgui.button("Button")) 
        counter[0]++;

    imgui.sameLine(0f, -1f);
    imgui.text("counter = " + counter[0]);

    if (imgui.smallButton("Exit")) {
        Minecraft.getMinecraft().displayGuiScreen((GuiScreen) null);
    }

    imgui.render();
    implGl3.renderDrawData(imgui.getDrawData());
}

} `

Im trying to implement ImGui into minecraft, so I ported minecraft to lwjgl3 and tried to do this, I don't know much about JVM/C so don't know the issue here.

Reproduction

erm...

Relevant log output

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff9df672a5e, pid=16276, tid=0x000000000000403c
#
# JRE version: OpenJDK Runtime Environment (8.0_352-b08) (build 1.8.0_352-b08)
# Java VM: OpenJDK 64-Bit Server VM (25.352-b08 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [nvoglv64.dll+0xf12a5e]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\OneDrive\Programming\MCP\Coder Pack\jars\hs_err_pid16276.log
[14:46:25] [Server thread/INFO]: Saving and pausing game...
#
# If you would like to submit a bug report, please visit:
#   https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

JVM Crashlog
[hs_err_pid16276.log](https://github.com/SpaiR/imgui-java/files/11246305/hs_err_pid16276.log)
ryanftpsh commented 1 year ago

Sorry im bad at markdown :P

ryanftpsh commented 1 year ago

I didn't initialize ImGuiImplGl3 🤦