imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Imgui in minecraft yields nondeterministic rendering issues

Open zeroeightysix opened this issue 5 years ago • 19 comments

This might be related to #112, #99 or #96. My setup is comparable to all three issues.

Setup

  • build.gradle: To work around #112, the fix mentioned in that thread are being used: The rest of the file is omitted for brevity.
compile "com.github.kotlin-graphics:imgui:-SNAPSHOT"
compile 'com.github.kotlin-graphics:uno-sdk:f528113bf45e43406953d6881915467d85a20881'
compile 'com.github.kotlin-graphics.glm:glm:1b4ac18dd1a3c23440d3f33596688aac60bc0141'
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.3.61'
  • MinecraftScreen.java: The minecraft screen (GUI) (see #99 examples, and the example on the wiki) Source code

Problem

Imgui's rendering screws up randomly, depending on at what time implGl3 = new ImplGL3(); (in MinecraftScreen) is called.

Sometimes it renders just fine: image

Sometimes it doesn't render at all.

Sometimes it only draws some glyphs, varying in readability: image More readable: image

Sometimes all text gets cut off slightly. image

How the rendering screws up depends on the current instance of ImplGL3. Each time the player invokes a command causing MinecraftScreen#reload (this method) to be invoked (thus, creating a new instance of ImplGl3), the rendering changes, randomly, to any of the above.

I'm assuming this has something to do with the openGL state imgui sets up for itself. Changing the GL state before any call to implGl3.renderDrawData does not affect how the windows are drawn.

Sorry for opening all of these issues! Thanks for your continued help.

zeroeightysix avatar Dec 19 '19 15:12 zeroeightysix

I'll look into that in this holidays, do you have a SSCCE I can use it to debug it?

Ps: opening issues is actually a great help

elect86 avatar Dec 19 '19 15:12 elect86

I created a repository here. I believe you need minecraft installed on your system for fabric to work.

Assuming you are using IDEA:

  1. Import the project from the build.gradle
  2. Wait for fabric to finish generating sources, etc.
  3. Run ./gradlew idea, to generate the run configurations 3.1. You may have to restart your IDE for the run configurations to show up!
  4. Run the newly generated 'Minecraft Client' run configuration.

If everything went right, minecraft will start up and in the console will appear:

[main/INFO]: [STDOUT]: Hello imgui!
  1. Create a new world (Singleplayer > Create new world > Create new world)
  2. Once ingame, press Y. This will open the imgui screen. 2.1 Press R to reload the imgui screen.

zeroeightysix avatar Dec 19 '19 15:12 zeroeightysix

I found this issue a while back, but could only crash when trying to run it myself! Thank you for finding this! What OS are you using? I think Windows, which I was using, will not work to re-create, since mine would always crash.

On Thu, Dec 19, 2019, 09:57 Ridan Vandenbergh [email protected] wrote:

I created a repository here https://github.com/zeroeightysix/fabric-example-mod. I believe you need minecraft installed on your system for fabric to work.

Assuming you are using IDEA:

  1. Import the project from the build.gradle
  2. Wait for fabric to finish generating sources, etc.
  3. Run ./gradlew idea, to generate the run configurations 3.1. You may have to restart your IDE for the run configurations to show up!
  4. Run the newly generated 'Minecraft Client' run configuration.

If everything went right, minecraft will start up and in the console will appear:

[main/INFO]: [STDOUT]: Hello imgui!

  1. Create a new world (Singleplayer > Create new world > Create new world)
  2. Once ingame, press Y. This will open the imgui screen. 2.1 Press R to reload the imgui screen.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kotlin-graphics/imgui/issues/114?email_source=notifications&email_token=ADTJ6QEQNBQD2BJSN7QASRLQZOKYFA5CNFSM4J5I3GK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHKB2XQ#issuecomment-567549278, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTJ6QCGNTBGHOVNSS4KX2LQZOKYFANCNFSM4J5I3GKQ .

Sylvyrfysh avatar Dec 19 '19 16:12 Sylvyrfysh

I found this issue a while back, but could only crash when trying to run it myself! Thank you for finding this! What OS are you using? I think Windows, which I was using, will not work to re-create, since mine would always crash.

I'm on linux.

Edit: I'll try to reproduce this issue on windows.

zeroeightysix avatar Dec 19 '19 16:12 zeroeightysix

Turns out it's even worse on windows. The problem stays the same, with nondeterministic rendering when the GUI screen is opened. However, sometimes the program is killed upon either opening the screen or always killed when pressing R to renew the ImplGl3 instance. No crash, no error, no nothing. Just a bogus exit code (-1073741819).

I got one JVM crash though (also appearing in nondeterministic nature): jvm_crash.txt hs_err_pid5428.log

Oh, what fun this is to debug..

Edit: The hex number in EXCEPTION_ACCESS_VIOLATION (0xc0000005) mentioned in jvm_crash.txt is the aforementioned -1073741819 (0xc0000005 - (2^32 - 1))

zeroeightysix avatar Dec 19 '19 17:12 zeroeightysix

Instinct says to me that we're using a different texture format than Minecraft and incorrectly setting it

On Thu, Dec 19, 2019, 11:27 Ridan Vandenbergh [email protected] wrote:

Turns out it's even worse on windows. The problem stays the same, with nondeterministic rendering when the GUI screen is opened. However, sometimes the program is killed upon either opening the screen or always killed when pressing R to renew the ImplGl3 instance. No crash, no error, no nothing. Just a bogus exit code ( -1073741819).

I got one JVM crash though (also appearing in nondeterministic nature): jvm_crash.txt https://github.com/kotlin-graphics/imgui/files/3984814/jvm_crash.txt hs_err_pid5428.log https://github.com/kotlin-graphics/imgui/files/3984813/hs_err_pid5428.log

Oh, what fun this is to debug..

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kotlin-graphics/imgui/issues/114?email_source=notifications&email_token=ADTJ6QG4HHDWC6EDR73DEKLQZOVIDA5CNFSM4J5I3GK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHKKRKQ#issuecomment-567584938, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTJ6QCXM3LRF6OBNTHTXETQZOVIDANCNFSM4J5I3GKQ .

Sylvyrfysh avatar Dec 19 '19 17:12 Sylvyrfysh

Instinct says to me that we're using a different texture format than Minecraft and incorrectly setting it

How come the crashes and rendering is so unpredictable though? If you were using another format, I'd assume it'd crash all the time, or render wrongly all the time

zeroeightysix avatar Dec 19 '19 17:12 zeroeightysix

The crashes may be because of the texture being placed in different places in memory. Before the end leads to weird results due to reading nulls, at the end causes an access violation after we read past the end that we think is there. The rendering incorrectly stumps me more here. This doesn't really explain the different rendering, but my idea is that Minecraft may use different pixel store alignments for different textures? Or potentially something with texture arrays causing something goofy with upload offsets, like empty 10x10 images being placed before it? I'm not GL expert, so I really don't know. But there are a lot of places this could come from.

Sylvyrfysh avatar Dec 19 '19 17:12 Sylvyrfysh

4. Run the newly generated 'Minecraft Client' run configuration.

I get:

bad class file: C:\Users\elect.gradle\caches\modules-2\files-2.1\com.github.kotlin-graphics.glm\glm\1b4ac18dd1a3c23440d3f33596688aac60bc0141\e7be1f06acfd1647d34b2223e516971eb62479ab\glm-1b4ac18dd1a3c23440d3f33596688aac60bc0141.jar(glm_/vec2/Vec2.class) class file has wrong version 55.0, should be 52.0 Please remove or make sure it appears in the correct subdirectory of the classpath.

Which jdk do you use?

elect86 avatar Jan 08 '20 10:01 elect86

Which jdk do you use?

Well, it's complicated. I've ran into this issue as well (and figured I'd fix it later, by updating @AlexApps99's branches)

I temporarily fixed it by setting the project SDK to java 11.0.5 (OpenJDK), and the project language level to 8:

image

zeroeightysix avatar Jan 08 '20 14:01 zeroeightysix

Same.

Could you try to replicate? Delete the project and re-clone

elect86 avatar Jan 08 '20 18:01 elect86

Same.

Could you try to replicate? Delete the project and re-clone

Sorry for the late response.

I am able to replicate the issue you described and using the configuration I posted above, I am able to get it to run anyways. The original bug this report is about is still there as well.

zeroeightysix avatar Jan 14 '20 19:01 zeroeightysix

I have 11.0.1, let me try 11.0.5

elect86 avatar Jan 14 '20 19:01 elect86

@zeroeightysix, give it a try, thanks to tests, I fixed tons of bugs and corner cases, a couple of crash allocation bugs included

elect86 avatar Mar 04 '20 14:03 elect86

@zeroeightysix, give it a try, thanks to tests, I fixed tons of bugs and corner cases, a couple of crash allocation bugs included

Unfortunately I am still able to reproduce this issue.

However, the amount of crashes I randomly encounter has decreased significantly (recently, none). Good work!

zeroeightysix avatar Mar 04 '20 17:03 zeroeightysix

May I see one log of these still existing crashes?

elect86 avatar Mar 04 '20 21:03 elect86

May I see one log of these still existing crashes?

Looking at my remaining logs.. looks like it won't be anything new! My last crash was Feb 2, meaning I haven't had any crashes since fc381b72c0c75fb9f4199e7387cc629414ac9b38 - I'm going to assume the commits after have fixed them all.

If I do run into a crash again, I'll let you know.

zeroeightysix avatar Mar 04 '20 21:03 zeroeightysix

Nice, let's keep this open still for a while and if there wont be still any crashe, we'll consider it resolved

elect86 avatar Mar 04 '20 22:03 elect86

I've managed to avoid both the crashes and rendering issues by initializing ImplGL3 right after the Minecraft window is created in WindowProvider::createWindow.

@Mixin(WindowProvider.class)
public class WindowProviderInit {
    @Inject(at = @At("TAIL"), method = "createWindow")
    public void onCreateWindow(WindowSettings settings, String videoMode, String title, CallbackInfoReturnable<Window> cir) {
        Window window = cir.getReturnValue();    
        // Initialize ImplGL3 here!
    }
}

yapht avatar Apr 12 '21 04:04 yapht