age-series / ElectricalAge

Electrical Age (ELN) is a Minecraft Mod offering the ability to perform large-scale in-game electrical simulations.
Other
65 stars 30 forks source link

Potential incompatibility with LWJGL3ify #308

Closed msparkles closed 6 months ago

msparkles commented 6 months ago

Crashes the game, sometimes, especially on disconnect.

FATAL ERROR in native method: Thread[#152,Netty Client IO #7,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.GL11.glDeleteLists(Native Method)
    at org.lwjglx.opengl.GL11.glDeleteLists(GL11.java:718)
    at mods.eln.misc.UtilsClient.glDeleteListsAllSafe(UtilsClient.kt:560)
    at mods.eln.client.ConnectionListener.onDisconnectedFromServerEvent(ConnectionListener.java:38)
    at cpw.mods.fml.common.eventhandler.ASMEventHandler_1652_ConnectionListener_onDisconnectedFromServerEvent_ClientDisconnectionFromServerEvent.invoke(.dynamic)
    at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
    at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140)
    at cpw.mods.fml.common.network.handshake.NetworkDispatcher.close(NetworkDispatcher.java:405)
    at io.netty.channel.DefaultChannelHandlerContext.invokeClose(DefaultChannelHandlerContext.java:560)
    at io.netty.channel.DefaultChannelHandlerContext.close(DefaultChannelHandlerContext.java:545)
    at io.netty.channel.ChannelOutboundHandlerAdapter.close(ChannelOutboundHandlerAdapter.java:71)
    at io.netty.channel.DefaultChannelHandlerContext.invokeClose(DefaultChannelHandlerContext.java:560)
    at io.netty.channel.DefaultChannelHandlerContext.close(DefaultChannelHandlerContext.java:545)
    at io.netty.channel.ChannelOutboundHandlerAdapter.close(ChannelOutboundHandlerAdapter.java:71)
    at io.netty.channel.DefaultChannelHandlerContext.invokeClose(DefaultChannelHandlerContext.java:560)
    at io.netty.channel.DefaultChannelHandlerContext.close(DefaultChannelHandlerContext.java:545)
    at io.netty.channel.DefaultChannelHandlerContext.close(DefaultChannelHandlerContext.java:423)
    at io.netty.channel.DefaultChannelPipeline.close(DefaultChannelPipeline.java:826)
    at io.netty.channel.AbstractChannel.close(AbstractChannel.java:177)
    at net.minecraft.network.NetworkManager.func_150718_a(NetworkManager.java:230)
    at net.minecraft.client.network.NetHandlerPlayClient.func_147253_a(NetHandlerPlayClient.java:636)
    at net.minecraft.network.play.server.S40PacketDisconnect.func_148833_a(SourceFile:32)
    at net.minecraft.network.play.server.S40PacketDisconnect.func_148833_a(SourceFile:9)
    at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:113)
    at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:317)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at ic2.core.network.RpcHandler.channelRead0(RpcHandler.java:129)
    at ic2.core.network.RpcHandler.channelRead0(RpcHandler.java:29)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at cpw.mods.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:210)
    at cpw.mods.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:47)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at mods.immibis.core.impl.NetworkingManager.channelRead(NetworkingManager.java:541)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at io.netty.handler.timeout.ReadTimeoutHandler.channelRead(ReadTimeoutHandler.java:149)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:100)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:480)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:447)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:341)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    at java.lang.Thread.runWith(java.base@21/Thread.java:1596)
    at java.lang.Thread.run(java.base@21/Thread.java:1583)
jrddunbr commented 6 months ago

I have no idea how to fix this. I'm hoping Cam can figure out what might be going on since he's been studying LWJGL and OpenGL stuff.

I'm sure there are plenty of problems that could cause this, the least of which being our models with broken normals or our homebrew obj renderer...

Caeleron commented 6 months ago

It looks like somebody destroyed the OpenGL context too early. I'm going to point my finger at lwjgl3ify since I can't find anything in ELN's codebase that does any kind of management of contexts; we just use the one Minecraft has already loaded. We could put a check into every cleanup function to make sure there is actually an OpenGL context to try to clean, but this really should be considered a bug in lwjgl3ify, not ELN.

jrddunbr commented 6 months ago

You're welcome to put out a PR for the fix if you identify one, I do plan to make some changes to our render code at some point (basically, kotlinizing it), but I don't see any point in supporting lwjgl3 on it's own. Is there a particular end to using it with that?

msparkles commented 6 months ago

@jrddunbr @Caeleron It seems that there's a similar bug where a crash would cause the same error in an earlier version of lwjgl3ify.

This is their fix: https://github.com/GTNewHorizons/lwjgl3ify/commit/869f8b39ae973547a0b830d1833db147cdd474c0

It seems that this is just a lwjgl3 thing, that you should add extra checks, and their patch is for mods which they can't fix/fork ('cause GTNH does have all the forks in the world...).

msparkles commented 6 months ago

Will try to implement something similar and report back if it fixes the issue.

msparkles commented 6 months ago

.......? It seems that that isn't the issue, it's that somehow, the event listener is on the netty thread? We're unfamiliar with forge...

The context exists and returns a Capability...

msparkles commented 6 months ago

Thank you @asiekierka for finding the method we were missing and then stealing the 2 hours of our life that we spent on researching for a solution and invalidating my feelings /j /coping

asiekierka commented 6 months ago