imgui: Minecraft example not working
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.
#
I’m not sure why this happens, i’m using exactly the same code as in the wiki.
Any help would be appreciated!
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 102
Commits related to this issue
- #99 debugs — committed to kotlin-graphics/imgui by Sylvyrfysh 5 years ago
For anyone who has stumbled upon this issue (and waiting for closure, presumably), i have taken an interest in this library and made a fabricmc template that works out of the box based on multiple issues and reports from this repository.
I have only tested this on linux, so i am unsure if issues still exist within windows.
https://github.com/breadbyte/fabric-example-imgui
First you have to run
./gradlew genSources, then depending on whether you use eclipse or intellij either./gradlew eclipseor./gradlew ideato generate the correct run configuration.For other editors you can use those settings as reference:
Might help: https://fabricmc.net/wiki/tutorial:setup
We may add an option to avoid propagating the esc key, whay to you think?
@breadbyte if you want to add a link in the Readme and/or add a wiki page about that, dont hesitate
As a sidenote, since I am no longer working on this, I will remove myself from the organization. Thanks for the wonderful libs you’ve given us!
I did get a native code crash the second time I ran it, so further testing may be required. Source is here: https://github.com/AlexApps99/MinecraftImgui It is written in Minecraft Forge instead of Fabric, so it should be more widely supported and stable, testing from others would be appreciated. The compiled jar is here: https://github.com/AlexApps99/MinecraftImgui/suites/247356077/artifacts/74693
To test it, just install Forge from this site: https://files.minecraftforge.net/ and put the jar in Forge’s mods folder.
Note: it only works on 1.14.4 because imgui uses some classes that are only available in newer versions of lwjgl
To use it just join a world then press <kbd>RIGHT SHIFT</kbd> to open, press the exit button on the menu to exit.
Will try to do the bulk of the fixes tomorrow, hopefully it’ll work
I got it working with the zip you provided and a few changes:
I changed
MinecraftClientMixintoMixinKeyboardand changed the mixin to this:This way we can invoke imgui in-game by pressing a key (when we’re sure everything of opengl/glfw etc has already been handled by minecraft)
And simply added
imgui.render();to your render method inTestScreen:I never ran into a JVM crash though. I’m on linux, so our natives are different. Can you try the changes above and see if it works?