kotlin-graphics / imgui

Bloat-free Immediate Mode Graphical User interface for JVM with minimal dependencies (rewrite of dear imgui)
MIT License
599 stars 36 forks source link

Minecraft example not working #99

Open niklasbuesing opened 5 years ago

niklasbuesing commented 5 years ago

Hi!

I'm trying to use imgui in a Minecraft mod i'm making, so i started with the example in the wiki:

public class TestScreen extends Screen {

    private static ImGui imgui = ImGui.INSTANCE;

    private static ImplGL3 implGl3;
    private static ImplGlfw implGlfw;

    static {
        GlfwWindow window = GlfwWindow.from(MinecraftClient.getInstance().window.getHandle());
        window.makeContextCurrent();
        new Context();
        implGlfw = new ImplGlfw(window, false, null);
        implGl3 = new ImplGL3();
    }

    public TestScreen () {
        super(new TextComponent("Test Screen"));
    }

    @Override
    public void render(int x, int y, float partialTicks) {

        implGl3.newFrame(); // JVM crashes here
        implGlfw.newFrame();
        imgui.newFrame();

        imgui.text("Hello Minecraft!");

        implGl3.renderDrawData(imgui.getDrawData());

    }
}

Upon showing the screen however, the jvm crashes:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006b2e0e20, pid=2940, tid=0x00000000000059f0
#
# JRE version: Java(TM) SE Runtime Environment (8.0_211-b12) (build 1.8.0_211-b12)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.211-b12 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [nvoglv64.dll+0xc20e20]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

hs_err_pid2940.log

I'm not sure why this happens, i'm using exactly the same code as in the wiki.

Any help would be appreciated!

gurachan commented 4 years ago

@breadbyte very thanks.

I noticed when using inputTextEx and using

private static byte[] msg = new byte[256];

so for instance you make a

ArrayList<String> items = new ArrayList<String>();

you trim the msg by

   String _data = new String(msg).trim();

then add it to item

 items.add(_data);

then clear the msg by

msg = new byte[256];

there are 1/10 chances that you will get ??? next to the text you just say. am i doing it wrong?

I tried the string version too .. Using inputText that uses String as buffer is not helpful .. so if you create a string that has value "hello" then use that as buffer ... you can only type 5 letters or the total of letters.

also if you clear the msg buffer while u still typing so your focus is still on the input box.. the text is not gone... unless u click somewhere else. it will be nice if they act as a normal text input where they respect what is the current value regardless of focus

elect86 commented 3 years ago

Hey,

what's the status on this one?