kotlin-graphics / imgui

Bloat-free Immediate Mode Graphical User interface for JVM with minimal dependencies (rewrite of dear imgui)
MIT License
597 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!

AlexApps99 commented 4 years ago

I found this class (gln.identifiers.GlVertexArray), which is probably an equivalent to the missing one from earlier, but I couldn't find an equivalent to GlBufferEnum. Will continue my search.

Edit: Found this commit kotlin-graphics/gln@aeb4850

Sylvyrfysh commented 4 years ago

If I remember correctly, Imgui is using an old version of gln. If you forked gln head, that might be the issue. You probably want to fork off the commit found in imgui Gradle.

On Mon, Sep 30, 2019, 00:25 AlexApps99 notifications@github.com wrote:

I found this class (gln.identifiers.GlVertexArray) https://github.com/kotlin-graphics/gln/blob/jdk8/src/main/kotlin/gln/identifiers/vertexArray.kt#L59, which is probably an equivalent to the missing one from earlier, but I couldn't find an equivalent to GlBufferEnum. Will continue my search.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kotlin-graphics/imgui/issues/99?email_source=notifications&email_token=ADTJ6QHIMIY6X2Y5NGSJR73QMGETLA5CNFSM4HYGJBD2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD74OQWA#issuecomment-536406104, or mute the thread https://github.com/notifications/unsubscribe-auth/ADTJ6QHMXYIJ5R6VZASKIVLQMGETLANCNFSM4HYGJBDQ .

AlexApps99 commented 4 years ago

That is a good point, but it would be better for Imgui to use up-to-date libraries instead. I will research a solution to the removal of GlBufferEnum, as I would prefer to use the latest version.

AlexApps99 commented 4 years ago

I have managed to update it to use the latest branch with a two-line modification, it builds now. Thanks for the help, will create a demo soon to test it out.

elect86 commented 4 years ago

~What do you mean by undefined? They should be there under gln.identifiers~

I missed the last 4 replies, you can also get rid of GlBufferEnum, but I see you already solved

Sorry about the up-to-date libs, you are totally right, but gln is still under work

AlexApps99 commented 4 years ago

Ah, makes sense...

Thanks for all of the help, I really appreciate all the work you've put into these wonderful libraries :)

elect86 commented 4 years ago

Thank you for supporting, appreciated

AlexApps99 commented 4 years ago

ImguiMinecraft :tada:

elect86 commented 4 years ago

Sweet, you may want to update the wiki about that to help other people

AlexApps99 commented 4 years ago

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 RIGHT SHIFT to open, press the exit button on the menu to exit.

Screenshot_2019-10-02_15-53-02 Screenshot of it working on OpenJDK8 (Arch Linux)

AlexApps99 commented 4 years ago

If others can test this on Windows and post their error messages (if any) I would be thankful :)

Please let me know if it works or not

elect86 commented 4 years ago

Hey Alex,

did you solve for the inputs?

AlexApps99 commented 4 years ago

No, I haven't yet.

elect86 commented 4 years ago

Their callbacks get passed here

AlexApps99 commented 4 years ago

Does key input work on Linux outside of Minecraft? It seems that it only gets input on Windows (unsure) https://github.com/kotlin-graphics/imgui/blob/master/imgui-core/src/main/kotlin/imgui/windowsIme/imeListener.kt#L31-L35

AlexApps99 commented 4 years ago

I tried to implement the callbacks myself, but the values referenced seem to be private. Are there any getters/setters for these values?

Code: https://github.com/AlexApps99/MinecraftImgui/blob/master/src/main/java/com/example/examplemod/MyMinecraftScreen.java#L67-L87

Compilation errors: https://github.com/AlexApps99/MinecraftImgui/commit/0c6d54cd0982b0c2ac3f0074fa27c6dfb5407cb2/checks?check_suite_id=262118357#step:4:307

Sylvyrfysh commented 4 years ago

IMM is windows only, Linux does not touch it. Additionally, there are not currently callbacks, but feel free to add them. I'll try to look into this on Monday

elect86 commented 4 years ago

@AlexApps99, do you need the IME on Linux?

AlexApps99 commented 4 years ago

I don't think so, I wrote my own callbacks to gather input but there's no setter/variable to save input to

elect86 commented 4 years ago

@AlexApps99 try io.getKeysDown()

AlexApps99 commented 4 years ago

That's a getter, I need to set the keys that are down

elect86 commented 4 years ago

it's a boolean array

io.getKeysDown()[i] = true

elect86 commented 4 years ago

@AlexApps99 any news?

Consider closing if resolved

AlexApps99 commented 4 years ago

@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.

AlexApps99 commented 4 years ago

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!

breadbyte commented 4 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

elect86 commented 4 years ago

@breadbyte if you want to add a link in the Readme and/or add a wiki page about that, dont hesitate

melvyn2 commented 4 years ago

@breadbyte When I tried your fabric template, I still got class file has wrong version 55.0, should be 52.0. I'm probably doing something wrong, but I can't find out what.

AlexApps99 commented 4 years ago

What that usually means is that you're compiling with the wrong version of Java (52 is Java 8, 55 is Java 11)

melvyn2 commented 4 years ago

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 jdk8 branch, but that cause a bunch of other errors. Before I go further in trying to fix them, I'm trying to see if the template creator ran into this.

elect86 commented 4 years ago

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?

melvyn2 commented 4 years ago

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. That gave me a crash of java.lang.NullPointerException: A required function is missing: glfwGetMonitorWorkarea. After realizing this is platform specific code, I tried the template on linux, and everything worked out-of-box. So, the real issue is that something breaks the template on macOS, but it works fine on linux.

breadbyte commented 4 years ago

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.

elect86 commented 4 years ago

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. That gave me a crash of java.lang.NullPointerException: A required function is missing: glfwGetMonitorWorkarea. After realizing this is platform specific code, I tried the template on linux, and everything worked out-of-box. So, the real issue is that something breaks the template on macOS, but it works fine on linux.

According to Spasi, the error on macos

It means there's a version mismatch between the Java GLFW bindings and the corresponding natives.

@melvyn2 can you investigate in the glfw version you actually use on macos?

melvyn2 commented 4 years ago
$ otool -L .gradle/caches/fabric-loom/natives/1.15.2/libglfw.dylib
.gradle/caches/fabric-loom/natives/1.15.2/libglfw.dylib:
    @rpath/libglfw.3.dylib (compatibility version 3.0.0, current version 3.3.0)
        ...
elect86 commented 4 years ago

It doesn't look like it's loading LWJGL's glfw binary

HvHBlackTeal commented 4 years ago

Hello, what's wrong with my build.gradle? I can't use jdk8 branch.

buildscript {
    repositories {
        maven { url = 'https://files.minecraftforge.net/maven' }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
    }
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'

version = '1.0'
group = 'com.example.examplemod' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'examplemod'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

repositories {
    // ImGUI
    maven {
        url = "https://jitpack.io"
    }
    jcenter()
    mavenCentral()
}

dependencies {
    // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
    // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
    // The userdev artifact is a special name and will get all sorts of transformations applied to it.
    minecraft 'net.minecraftforge:forge:1.14.4-28.2.0'

    // ImGUI
    ["imgui-core", "imgui-gl", "imgui-glfw"].each {
        compile("com.github.kotlin-graphics.imgui:$it:jdk8-SNAPSHOT") {
            exclude group: "org.lwjgl"
        }
    }

}

// Example for how to get properties into the manifest for reading by the runtime..
jar {
    manifest {
        attributes([
                "Specification-Title": "examplemod",
                "Specification-Vendor": "examplemodsareus",
                "Specification-Version": "1", // We are version 1 of ourselves
                "Implementation-Title": project.name,
                "Implementation-Version": "${version}",
                "Implementation-Vendor" :"examplemodsareus",
                "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
        ])
    }
}

minecraft {
    // The mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   Snapshot are built nightly.
    // stable_#            Stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not always work.
    // Simply re-run your setup task after changing the mappings to update your workspace.
    mappings channel: 'snapshot', version: '20190719-1.14.3'

    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

    // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

    // Default run configurations.
    // These can be tweaked, removed, or duplicated as needed.
    runs {
        client {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

            mods {
                examplemod {
                    source sourceSets.main
                }
            }
        }

        server {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

            mods {
                examplemod {
                    source sourceSets.main
                }
            }
        }

        data {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

            args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/')

            mods {
                examplemod {
                    source sourceSets.main
                }
            }
        }
    }
}

image Console Error Log:

Could not resolve all files for configuration ':compileClasspath'.
> Could not find com.github.kotlin-graphics.glm:glm:jdk8-SNAPSHOT.
  Searched in the following locations:
    - https://jitpack.io/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/maven-metadata.xml
    - https://jitpack.io/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-0ffefa69c4-1.pom
    - https://jitpack.io/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-0ffefa69c4-1.jar
    - https://jcenter.bintray.com/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/maven-metadata.xml
    - https://jcenter.bintray.com/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.pom
    - https://jcenter.bintray.com/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.jar
    - https://repo.maven.apache.org/maven2/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/maven-metadata.xml
    - https://repo.maven.apache.org/maven2/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.pom
    - https://repo.maven.apache.org/maven2/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.jar
    - https://files.minecraftforge.net/maven/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/maven-metadata.xml
    - https://files.minecraftforge.net/maven/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.pom
    - https://files.minecraftforge.net/maven/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.jar
    - file:/C:/Users/BlackTeal/.gradle/caches/forge_gradle/bundeled_repo/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/maven-metadata.xml
    - file:/C:/Users/BlackTeal/.gradle/caches/forge_gradle/bundeled_repo/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.pom
    - file:/C:/Users/BlackTeal/.gradle/caches/forge_gradle/bundeled_repo/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.jar
    - https://libraries.minecraft.net/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/maven-metadata.xml
    - https://libraries.minecraft.net/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.jar
    - https://repo.maven.apache.org/maven2/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/maven-metadata.xml
    - https://repo.maven.apache.org/maven2/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.pom
    - https://repo.maven.apache.org/maven2/com/github/kotlin-graphics/glm/glm/jdk8-SNAPSHOT/glm-jdk8-SNAPSHOT.jar
  Required by:
      project : > com.github.kotlin-graphics.imgui:imgui-core:jdk8-SNAPSHOT:76fb7ed8bf-1
      project : > com.github.kotlin-graphics.imgui:imgui-gl:jdk8-SNAPSHOT:76fb7ed8bf-1
      project : > com.github.kotlin-graphics.imgui:imgui-glfw:jdk8-SNAPSHOT:76fb7ed8bf-1
      project : > com.github.kotlin-graphics.imgui:imgui-gl:jdk8-SNAPSHOT:76fb7ed8bf-1 > com.github.kotlin-graphics.uno-sdk:uno-core:jdk8-SNAPSHOT:b51033d51d-1
      project : > com.github.kotlin-graphics.imgui:imgui-gl:jdk8-SNAPSHOT:76fb7ed8bf-1 > com.github.kotlin-graphics.uno-sdk:uno-gl:jdk8-SNAPSHOT:b51033d51d-1
      project : > com.github.kotlin-graphics.imgui:imgui-core:jdk8-SNAPSHOT:76fb7ed8bf-1 > com.github.kotlin-graphics:uno-sdk:jdk8-SNAPSHOT:b51033d51d-1 > com.github.kotlin-graphics.uno-sdk:uno-awt:jdk8-SNAPSHOT:b51033d51d-1

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
elect86 commented 4 years ago

@HvHBlackTeal glm now doesn't have anymore 2 module, that means this: com.github.kotlin-graphics.glm:glm:jdk8-SNAPSHOT

shall be instead as follow com.github.kotlin-graphics:glm:jdk8-SNAPSHOT

HvHBlackTeal commented 4 years ago

But I'm not using

com.github.kotlin-graphics.glm:glm:jdk8-SNAPSHOT

on my code, I'm using

["gl", "glfw", "core"].each {
    implementation("com.github.kotlin-graphics.imgui:imgui-$it:jdk8-SNAPSHOT") {
        com.github.kotlin-graphics.glm:glm:jdk8-SNAPSHOT
    }
}

to import ImGui, using

implementation("com.github.kotlin-graphics:glm:jdk8-SNAPSHOT")
["gl", "glfw", "core"].each {
    implementation("com.github.kotlin-graphics.imgui:imgui-$it:jdk8-SNAPSHOT") {
        exclude group: "org.lwjgl"
    }
}

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.

elect86 commented 4 years ago

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

elect86 commented 4 years ago

@HvHBlackTeal ~65954961~ 70aabce0

gurachan commented 3 years ago

any news?

zeroeightysix commented 3 years ago

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.

gurachan commented 3 years ago

@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 :'(

sad

gurachan commented 3 years ago

another example that I can't type after I reopen the screen after typing

SADD2

breadbyte commented 3 years ago

The issues @Dj-jom2x are experiencing seem to be issues from my template specifically. I've fixed it in my template.

https://github.com/breadbyte/fabric-example-imgui/commit/0b11740e1776cdffe9e704cf2f0347d4dc6198ec The issue seems to be that the esc key was also propagating into imgui, causing imgui to also handle the esc key. I've decided to drop the esc key from being processed into imgui at all, since Minecraft's esc key handler would be more useful in this case. This is just a quick fix, so if there's a better way to handle this, please do tell me.

gurachan commented 3 years ago

The issues @Dj-jom2x are experiencing seem to be issues from my template specifically. I've fixed it in my template.

breadbyte/fabric-example-imgui@0b11740 The issue seems to be that the esc key was also propagating into imgui, causing imgui to also handle the esc key. I've decided to drop the esc key from being processed into imgui at all, since Minecraft's esc key handler would be more useful in this case. This is just a quick fix, so if there's a better way to handle this, please do tell me.

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..

elect86 commented 3 years ago

We may add an option to avoid propagating the esc key, whay to you think?

gurachan commented 3 years ago

@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.

breadbyte commented 3 years ago

@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. Although minecraft has a shouldCloseOnEsc option, it's set to true by default, making imgui's esc key handler impossible to use due to, well, the screen has closed before anything useful could come out of it, so i don't know if it should be set as a toggle on imgui because the option could be toggled independently outside of imgui.