GregTechCE / GregTech

GregTech rewrite for modern versions of Minecraft
GNU Lesser General Public License v3.0
271 stars 150 forks source link

[BUG] Infinite recursion when connecting GTCE cables to Compact Machine tunnels #1374

Open md5i opened 3 years ago

md5i commented 3 years ago

Describe the bug As a test, I created a compact machine and placed it next to an active Gregtech Community Edition cable. I added a tunnel to in the compact machine to the side with the cable. When I placed a GTCE cable next to the tunnel, the game crashed. The crash is due to infinite recursion in CableEnergyContainer between dispatchEnergyToNode() and acceptEnergyFromNetwork(). The crash is persistent between reloads, so I have had to restore from backup.

Versions Forge: 14.23.5.2847 GTCE: 1.10.1.557 Modpack: FTB Interactions 2.0.10 found (from FTB discord) at https://drive.google.com/file/d/1maGmng2twpUpZ-ZTBEBHPtEJPTmRN_d4/view Addons: none

Setup Playing Solo

Steps To Reproduce 1) Place a Gregtech Advanced Diesel Generator down. 2) Fill the generator with fuel (Diesel). 3) Connect a ~copper~ manasteel cable to the generator's output. 4) Place the compact machine next to the cable. 5) Enter the machine and place a tunnel on the wall that connects to the external cable. 6) Place a ~copper~ manasteel cable next to the tunnel. 7) Crash.

Note: I originally wrote "copper cable" above. But in practice, I used the manasteel cables added by FTB Interactions. They are MV cables with a loss per block set to 0 and have an amperage of 4. When I retried the experiment using copper cables, no crash happened. So this may be considered specific to FTB Interactions.

Expected behavior Since GTCE seems to be using Forge capabilities, I was expecting the cable to transmit energy into the compact machine through the tunnel. In the worst case, I expected the cables not to connect at all through the tunnel.

Relevant portion of crash log:

[19:58:35] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking block entity
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:773) ~[MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:668) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:185) ~[chd.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_275]
Caused by: java.lang.StackOverflowError
    at net.minecraft.world.World.getChunk(World.java:305) ~[amu.class:?]
    at net.minecraft.world.World.getTileEntity(World.java:2402) ~[amu.class:?]
    at org.dave.compactmachines3.tile.TileEntityTunnel.getCapability(TileEntityTunnel.java:95) ~[TileEntityTunnel.class:?]
    at gregtech.common.pipelike.cable.tile.CableEnergyContainer.dispatchEnergyToNode(CableEnergyContainer.java:88) ~[CableEnergyContainer.class:?]
    at gregtech.common.pipelike.cable.tile.CableEnergyContainer.acceptEnergyFromNetwork(CableEnergyContainer.java:46) ~[CableEnergyContainer.class:?]
    at gregtech.common.pipelike.cable.tile.CableEnergyContainer.dispatchEnergyToNode(CableEnergyContainer.java:90) ~[CableEnergyContainer.class:?]
    at gregtech.common.pipelike.cable.tile.CableEnergyContainer.acceptEnergyFromNetwork(CableEnergyContainer.java:46) ~[CableEnergyContainer.class:?]
    at gregtech.common.pipelike.cable.tile.CableEnergyContainer.dispatchEnergyToNode(CableEnergyContainer.java:90) ~[CableEnergyContainer.class:?]
    at gregtech.common.pipelike.cable.tile.CableEnergyContainer.acceptEnergyFromNetwork(CableEnergyContainer.java:46) ~[CableEnergyContainer.class:?]
    at gregtech.common.pipelike.cable.tile.CableEnergyContainer.dispatchEnergyToNode(CableEnergyContainer.java:90)
...
LAGIdiot commented 3 years ago

Thank you for creating this issue.

This should be investigated. Our energy is probably not compatible with Compact Machine (if they are not using our energy API) but at least we should not crash game.

eutro commented 3 years ago

Compact Machine tunnels pass through Forge Capabilities, which should make it possible for it to be compatible.

ALongStringOfNumbers commented 3 years ago

I am having a hard time reproducing this issue on GTCE: 1.10.9.612 and Compact Machines: 3.0.18-b278. Specifically I am having a hard time getting the compact machine tunnel to connect to the cable that is placed outside the compact machine. In all the ways I have done so, the GTCE cable will not connect to the compact machine. Would you mind elaborating on how you got them to connect?

md5i commented 3 years ago

Okay, I just redid the experiment from within FTB Interactions. In that experiment I never saw the cables connect. However, if the cables are in place and power is "sent" though the cables the crash occurs. I'll see if I can't craft up a minimal example outside of that modpack.

md5i commented 3 years ago

Okay, I managed to create a minimal example. Minecraft: 1.12.2 Forge: 14.23.5.2854

Mod Version
CodeChicken Lib 3.2.3.358
Compact Machines 3 1.12.2-3.0.18-b278
CraftTweaker 2 1.12-4.1.20.612
GregTech Community Edition 1.10.9.612
Just Enough Items 4.16.1.301
The One Probe 1.12-1.4.28

In the scripts subdirectory, a file called _test.zs with the following contents:

#loader gregtech
import mods.gregtech.material.MaterialRegistry;
val materialManasteel = MaterialRegistry.createIngotMaterial(805, "manasteel", 0x3D78DB, "SHINY", 2);
materialManasteel.setCableProperties(128, 4, 0);

Any situation with a powered manasteel cable on the outside outside of a compact machine, a tunnel inside the machine to the side with the cable, and a cable adjacent to the tunnel on the inside of the machine causes the crash.

ALongStringOfNumbers commented 3 years ago

Ok, thank you for the reproduction steps.

This issue occurs only when the cables on either side of the compact machine (inside and outside) are the manasteel cables. It does not happen at all with the default GTCE cables, for which I tested with copper cables, and it does not occur when you attempt to use different cables on either side of the compact machine.

LAGIdiot commented 3 years ago

Okay, this just got more interesting and difficult. Thank you both for providing us with more information regarding this.

It seems that cables generated on custom material created via CT have (or miss) some property which causes this. So that should be vector for investigation.

Anyway it should be fixed as it is provided functionality by GTCE.

warjort commented 3 years ago

Some information on what is happening here (assuming you got the cables to connect):

Gregtech will see the compact machine on the outside as a machine and send it power when the diesel generator makes power available to the cable. The tunnel will forward the power to the cable on the inside. The cable sees this as the tunnel operating as power source and tries to dispatch the energy. The only place it sees is the tunnel which will forward the power to the cable on the outside. The cable on the outside will now see the compact machine as a power source like the original diesel generator. We are back to the start and so ... recursive death

warjort commented 3 years ago

You could put a battery box on the inside of the compact machine next the tunnel and it will work fine. The battery box only dispatches power in one direction, so don't point it back at the tunnel. :-)

warjort commented 3 years ago

I have figured out a way to get the cables to connect, but it is does not reproduce the problem.

What you do is place something that is an energy container on one side of the tunnel (e.g. a machine) then you can connect a cable to the other side. The tunnel gains the capability from the machine.

The problem is that removing the machine to replace it with a cable causes the other side to disconnect because block changes are transferred through the tunnel.

There might be a way to play with chunk loading to get this block update/disconnect not to happen but this doesn't sound like the circumstance of the original bug report?

warjort commented 3 years ago

The issue as I see it is that is not really a bug in GregTech since you shouldn't ever have the situation where 2 cables can connect to a tunnel. The tunnel should never provide the capability to one side when the other side is not present and so the cables should not connect.

There is nothing in that processing that depends on the material?

The most likely cause is the tunnel is providing the capability due to lag, a chunk loading issue or some other glitch?

But, the other glitch could be #1398 since this is an interdimensional thing.

sei-mwd commented 3 years ago

Is the fact that ordinary copper cables do not trigger the crash relevant at all?

warjort commented 3 years ago

Is the fact that ordinary copper cables do not trigger the crash relevant at all?

It would be for #1398 if there is a manasteel cable at the same block position as the compact machine or the tunnel in a different dimension. That would explain why copper cables didn't connect but manasteel cables do. The connection would be due to a spurious cable to cable connection rather than the capability passed through the tunnel.