Skip to content
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

Imgui in minecraft yields nondeterministic rendering issues #114

Open
zeroeightysix opened this issue Dec 19, 2019 · 19 comments
Open

Imgui in minecraft yields nondeterministic rendering issues #114

zeroeightysix opened this issue Dec 19, 2019 · 19 comments

Comments

@zeroeightysix
Copy link
Collaborator

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

Setup

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'

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
Copy link
Collaborator

elect86 commented Dec 19, 2019

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 added a commit to zeroeightysix/fabric-example-mod that referenced this issue Dec 19, 2019
@zeroeightysix
Copy link
Collaborator Author

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
Copy link
Collaborator

Sylvyrfysh commented Dec 19, 2019 via email

@zeroeightysix
Copy link
Collaborator Author

zeroeightysix commented Dec 19, 2019

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
Copy link
Collaborator Author

zeroeightysix commented Dec 19, 2019

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
Copy link
Collaborator

Sylvyrfysh commented Dec 19, 2019 via email

@zeroeightysix
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator

elect86 commented Jan 8, 2020

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
Copy link
Collaborator Author

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
Copy link
Collaborator

elect86 commented Jan 8, 2020

Same.

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

@zeroeightysix
Copy link
Collaborator Author

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
Copy link
Collaborator

elect86 commented Jan 14, 2020

I have 11.0.1, let me try 11.0.5

@elect86
Copy link
Collaborator

elect86 commented Mar 4, 2020

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

@zeroeightysix
Copy link
Collaborator Author

@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
Copy link
Collaborator

elect86 commented Mar 4, 2020

May I see one log of these still existing crashes?

@zeroeightysix
Copy link
Collaborator Author

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 fc381b7 - 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
Copy link
Collaborator

elect86 commented Mar 4, 2020

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

@yapht
Copy link

yapht commented Apr 12, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants