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

Imgui in minecraft yields nondeterministic rendering issues #114

Open zeroeightysix opened 4 years ago

zeroeightysix commented 4 years ago

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

Setup

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.

elect86 commented 4 years ago

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

zeroeightysix commented 4 years ago

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.
Sylvyrfysh commented 4 years ago

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 notifications@github.com 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 .

zeroeightysix commented 4 years ago

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 commented 4 years ago

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

Sylvyrfysh commented 4 years ago

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 notifications@github.com 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 .

zeroeightysix commented 4 years ago

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

Sylvyrfysh commented 4 years ago

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.

elect86 commented 4 years ago
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?

zeroeightysix commented 4 years ago

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

elect86 commented 4 years ago

Same.

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

zeroeightysix commented 4 years ago

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.

elect86 commented 4 years ago

I have 11.0.1, let me try 11.0.5

elect86 commented 4 years ago

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

zeroeightysix commented 4 years ago

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

elect86 commented 4 years ago

May I see one log of these still existing crashes?

zeroeightysix commented 4 years ago

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.

elect86 commented 4 years ago

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

yapht commented 3 years ago

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!
    }
}