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

Lazy load SHADER_HUE in GuiColorEditorHSV to prevent crashes from the class being loaded too early #82

Open
solonovamax opened this issue May 8, 2022 · 0 comments

Comments

@solonovamax
Copy link

I am currently using the InvMove mod, which does some cursed black magic, requiring classes to be loaded during the startup phase.
This is so it can identify non-mc screens & allow the user to enable/disable movement with those screens.

The code for loading the classes can be found here

However, this causes an issue with malilib, when it attempts to load GuiColorEditorHSV.
This is because it statically loads a ShaderProgram.
If this ShaderProgram is loaded during the startup phase, the following exception will be thrown:

FATAL ERROR in native method: Thread[Render thread,5,main]: No context is current or a function that is not available in the current context was called. The JVM will abort execution.
	at org.lwjgl.opengl.GL20C.glCreateProgram(Native Method)
	at org.lwjgl.opengl.GL20.glCreateProgram(GL20.java:188)
	at fi.dy.masa.malilib.render.shader.ShaderProgram.init(ShaderProgram.java:38)
	at fi.dy.masa.malilib.render.shader.ShaderProgram.<init>(ShaderProgram.java:27)
	at fi.dy.masa.malilib.gui.GuiColorEditorHSV.<clinit>(GuiColorEditorHSV.java:24)
	at java.lang.Class.forName0([email protected]/Native Method)
	at java.lang.Class.forName([email protected]/Class.java:383)
	at java.lang.Class.forName([email protected]/Class.java:376)
	at me.pieking1215.invmove.InvMoveConfig.readUnrecognizedConfig(InvMoveConfig.java:441)
	at me.pieking1215.invmove.InvMoveConfig.load(InvMoveConfig.java:336)
	at me.pieking1215.invmove.InvMove.init(InvMove.java:43)
	at me.pieking1215.invmove.fabric.InvMoveFabric.onInitializeClient(InvMoveFabric.java:35)
	at net.fabricmc.loader.impl.game.minecraft.Hooks$$Lambda$3914/0x0000000800b01850.accept(Unknown Source)
	at net.fabricmc.loader.impl.entrypoint.EntrypointUtils.invoke0(EntrypointUtils.java:47)
	at net.fabricmc.loader.impl.entrypoint.EntrypointUtils.invoke(EntrypointUtils.java:35)
	at net.fabricmc.loader.impl.game.minecraft.Hooks.startClient(Hooks.java:53)
	at fudge.notenoughcrashes.fabric.mixinhandlers.ModLoaders.fabricEntrypoints(ModLoaders.java:9)
	at net.minecraft.class_310.redirect$fdj000$catchFabricInit(class_310.java:21453)
	at net.minecraft.class_310.<init>(class_310.java:452)
	at net.minecraft.client.main.Main.main(Main.java:197)

A fix for this would be to lazy-load the ShaderProgram. It would be initialized to null, and only loaded when needed. Alternatively, move it to a separate class.

@solonovamax solonovamax changed the title Lazy load SHADER_HUE in GuiColorEditorHSV to prevent crashes from the class being loaded to early Lazy load SHADER_HUE in GuiColorEditorHSV to prevent crashes from the class being loaded too early May 8, 2022
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

1 participant