-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minecraft example not working #99
Comments
I'll forward you to this guy (#96), who did the same |
What does your |
I'm just using the default Fabric build.gradle, plus repositories {
...
maven { url = "https://jitpack.io" }
}
dependencies {
...
ext{
imguiVersion = "-SNAPSHOT"
}
["gl", "glfw", "core"].each {
implementation("com.github.kotlin-graphics.imgui:imgui-$it:$imguiVersion") {
exclude group: "org.lwjgl"
}
}
} I also tried the specific commit you used (fc9aad3), with the same result. Dependencies seem okay |
I tried it with several older fabric versions down to 1.14 trying to match your configuration, however it still crashes. Anyways, i don't know what i've done, but now it crashes "gracefully":
It's probably the same root cause, but i guess thats easier to debug. I've made a minimal demo, maybe you can take a look at how it differs from your project. |
Do you get any rendering at all? The code crashing inside the OpenGL natives leads me to believe that something is happening with the GL context in Minecraft that causes us to not have a proper GL context. This might be because you register your screen in the |
Tried that, but it unfortunately still crashes. Sometimes because getDrawData() returns null (#99 (comment)), sometimes the jvm crashes (#99 (comment)) I've also tried calling ImGui#render before calling ImplGL3#renderDrawData, not sure if that's still required, just saw it in the tests, but that also didn't help. |
Give me the output of this, please? TestScreen.kt public class TestScreen extends Screen {
private static ImGui imgui = ImGui.INSTANCE;
private static ImplGL3 implGl3;
private static ImplGlfw implGlfw;
static {
test();
GlfwWindow window = GlfwWindow.from(MinecraftClient.getInstance().window.getHandle());
window.makeContextCurrent();
new Context();
implGlfw = new ImplGlfw(window, false, null);
implGl3 = new ImplGL3();
}
public static void test() {
ImguiKt.setIMGUI_ENABLE_TEST_ENGINE(true);
ImguiKt.setImGuiTestEngineHook_PreNewFrame(() -> {
TestScreen.onNewFrame();
return null;
});
ImguiKt.setImGuiTestEngineHook_PostNewFrame(() -> {
TestScreen.onPostNewFrame();
return null;
});
ImguiKt.setImGuiTestEngineHook_ItemAdd((rect, integer) -> {
System.out.printf("Item added at %f %f sz %f %f\n", rect.getBl().getX(), rect.getBr().getY(), rect.getWidth(), rect.getHeight());
return null;
});
ImguiKt.setImGuiTestEngineHook_ItemInfo((id, string, itm1) -> {
System.out.printf("Item added id %d str %s int %d\n", id, string, itm1);
return null;
});
}
private static void onNewFrame() {
System.out.println("Pre-NewFrame");
}
private static void onPostNewFrame() {
System.out.println("Post-NewFrame");
}
public TestScreen () {
super(new TextComponent("Test Screen"));
}
@Override
public void render(int x, int y, float partialTicks) {
implGl3.newFrame();
implGlfw.newFrame();
imgui.newFrame();
imgui.text("Hello Minecraft!");
imgui.render();
implGl3.renderDrawData(imgui.getDrawData());
}
} |
Sure
|
Change the static block to this: test();
GlfwWindow window = GlfwWindow.from(MinecraftClient.getInstance().window.getHandle());
System.out.printf("GLFWWindow %d\n", MinecraftClient.getInstance().window.getHandle());
window.makeContextCurrent();
new Context();
implGlfw = new ImplGlfw(window, false, null);
implGl3 = new ImplGL3(); and does the GLFWWindow say it is 0? My line of thinking on this issue is that all crashes we've seen here have a common root cause of a bad window. When we set the context as current on a dead/bad/non-existent window, we lose all GL functions, leading to a crash in uploading the font texture. It would also crash in the IME setposition. Your null crash avoids this behavior by crashing before on window-specific code is called (besides font upload- the one hole with this theory), but this might be some GL client/server sync we're seeing that would generally only appear second frame or something. If not, i'll try to get my modding environment working and see if it will work. Thank you for sticking with us through this! |
Window seems fine
Also not sure if relevant, but sometimes i have to run it a few times because it crashes before anything is printed with the original exception in my first comment |
Even with the key toggle? |
Yep |
How do you start that? I see no |
First you have to run For other editors you can use those settings as reference: Might help: https://fabricmc.net/wiki/tutorial:setup |
weird
|
I got it working with the zip you provided and a few changes: I changed @Mixin(Keyboard.class)
public abstract class MixinKeyboard {
@Inject(method = "onKey", at = @At(value = "HEAD"))
public void onKey(long handle, int keycode, int scancode, int i3, int i4, CallbackInfo info) {
if (MinecraftClient.getInstance().player != null && MinecraftClient.getInstance().currentScreen == null) {
MinecraftClient.getInstance().openScreen(new TestScreen());
}
}
} 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.text("Hello Minecraft!");
imgui.render();
implGl3.renderDrawData(imgui.getDrawData());
... I never ran into a JVM crash though. I'm on linux, so our natives are different. |
Nope, still crashes :/
|
Now I get the jvm crash though.. in the ime, at |
So this appears to be a Windows specific issue, where the Imm Libraries cause a crash. I'll start playing around with e=that, just was finally able to get everything set up. @elect86 do you know if only one Imm context can be had per window, and possibly minecraft already has it? |
@elect86 I messes up the pulls on which branches but was planning to merge anyways. If you don't want the commit Cleanups/Javaifications, feel free to revert. @niklasbuesing Using commit ccbbf10, set The drawbacks to this method is that currently Imgui on minecraft will not receive IME events, so we'll have to see if we can reflect out the HWND MC has. |
Yep, works fine now! 👍 Thanks to everyone involved for their efforts. 😃 |
It's totally fine, let's merge it.. Nice workaround @Sylvyrfysh Btw, I double checked We might create an issue over there (https://github.com/FabricMC) to watch this issue in the long term and see if we find the culprit, I'm afraid this may have to do with something else under the hood.. (@niklasbuesing which repo would you suggest in their organization in this matter?) |
Can someone post a zip of their simple example? i keep getting the glTexture2D crashes when trying to actually fix this |
Example is not compiling for me on Java 8,
If there is any way I could get around this, I would appreciate it greatly. Edit: removed import as it was unused, ImGUI now says its' classpath is for Java 11.
|
It's probably worth asking, is this library compatible with Java 8, and compatible with Linux? |
Reading the build files seems to suggest this is a Java 11 library, how would I compile this for Java 8? |
Change the value on the line here to 8. Don't know if that will compile though |
Will keep you posted if it doesn't work, thanks |
I don't think it'll work in my case as JitPack hosts this library compiled for Java 11 too. |
@elect86 Sorry for the incredibly late response, I've been preoccupied by other things and I never made any additional progress. I am not the one who opened the issue, so if @niklasbuesing is ok with it this can be closed. |
As a sidenote, since I am no longer working on this, I will remove myself from the organization. |
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. |
@breadbyte if you want to add a link in the Readme and/or add a wiki page about that, dont hesitate |
@breadbyte When I tried your fabric template, I still got |
What that usually means is that you're compiling with the wrong version of Java (52 is Java 8, 55 is Java 11) |
I'm trying to compile with Java 8, but the template is using ImGui compiled for Java 11. I tried to switch it to the |
I'm about to give a refresh to all the libs, I'll do also for the jdk8 branch which kind of errors are you experiencing, @melvyn2? |
I was dealing with the wrong problem, actually. When I ran the template with Java 12, I got a native crash. I realized that OpenJ9 might be causing the issue, so I switched to HotSpot. |
Admittedly, I have not tested my template on both the Java 8 branch nor macOS as I don't have access to a macOS machine, and, for the record, I use AdoptOpenJDK 14 OpenJ9 on my machine. I will do some more testing around. |
According to Spasi, the error on macos
@melvyn2 can you investigate in the glfw version you actually use on macos? |
|
|
Hello, what's wrong with my build.gradle? I can't use jdk8 branch.
|
@HvHBlackTeal glm now doesn't have anymore 2 module, that means this: shall be instead as follow |
But I'm not using
on my code, I'm using
to import ImGui, using
also doesn't work and I get the same error, if I use default ImGui version but jdk8 glm, it says that ImGui classes are bad, they're 55.0 and should be 52.0, imgui-gl is causing this problem, if I implement this as jdk8, it tries do find glm/glm insteand of glm, doesn't find and the compilation fails, if I implement as java 11 it doesn't work because ImGui classes are bad, I'm trying to implement ImGui in a forge mod. |
I'm in the process of refreshing the jdk8 branches along the organizations, however I'm experiencing some troubles on uno-sdk and jpms I'll suppress the error to give you quickly the possibility to test |
any news? |
Assuming you are:
imgui works quite well in minecraft aside from the occasional occurence of #114 - of which I still haven't found the cause. |
@breadbyte this https://github.com/breadbyte/fabric-example-imgui is almost perfect ... this what happens if you leave the input open then close the screen. you cant type anymore :'( |
The issues @Dj-jom2x are experiencing seem to be issues from my template specifically. breadbyte/fabric-example-imgui@0b11740 |
it seems working just fine xD thanks. what I did for the temp fix. @Override
public void onClose() {
ctx.destroy(); // you need to create new context again because u destroy it
super.onClose();
} but every time you start the gui.. the currently selected tabs are being reset all opened collapsingHeader is being reset.. ... but your solution works great xD because it keeps the current selected tabs and current opened collapsingHeader.. |
We may add an option to avoid propagating the esc key, whay to you think? |
@breadbyte also stop the handle of the enter key.. it does the same bug.. can't type because it loses its focus so hard. I ignored keycode 257 now its fine. |
@Dj-jom2x I'm not sure if that would be a good idea, as the enter key provides actual useful functionality on imgui. I've decided to fix it on my template using an input buffer instead, when minecraft closes the screen, the input buffer sends a keyrelease for every input on the buffer. The reason why this is required is that when minecraft closes the screen, imgui cannot receive the keyreleased event, therefore on imgui's side it's as if it was never released at all. Adding an option to stop the esc key from being handled would be a good candidate for a default minecraft behavior, i think. |
@breadbyte very thanks. I noticed when using inputTextEx and using
so for instance you make a
you trim the msg by
then add it to item
then clear the msg by
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 |
Hey, what's the status on this one? |
Hi!
I'm trying to use imgui in a Minecraft mod i'm making, so i started with the example in the wiki:
Upon showing the screen however, the jvm crashes:
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!
The text was updated successfully, but these errors were encountered: