TeamDman / SuperFactoryManager

Mozilla Public License 2.0
49 stars 19 forks source link

Duplication glitch using redstone trigger #27

Closed Caraxi closed 5 years ago

Caraxi commented 5 years ago

Possibly related to #17 but with some more specific requirements for reproduction.

Reproduction

Create the following layout of blocks using the Machine Inventory Manager, a redstone receiver and two inventories. Layout

The following instructions in the Machine Inventory Manager:

Trigger

Input

Output

Program

Place some items in the input chest (A) and press the button. The output chest (B) will then be filled with the item from the input chest.

Versions

Minecraft 1.12.2 Minecraft Coder Pack 9.42 Forge Mod Loader 8.0.99.99 Minecraft Forge 14.23.5.2795 Super Factory Manager 2.0.12

Kanzuke117 commented 5 years ago

Executing this on a sever seems to cause a stackoverflow exception most of the time, an example below:

[23:09:40] [Server thread/FATAL] [net.minecraft.server.MinecraftServer]: Error executing task
java.util.concurrent.ExecutionException: net.minecraft.util.ReportedException: Exception while updating neighbours
    at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_202]
    at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_202]
    at net.minecraft.util.Util.func_181617_a(SourceFile:47) [h.class:?]
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:723) [MinecraftServer.class:?]
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:397) [nz.class:?]
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_202]
Caused by: net.minecraft.util.ReportedException: Exception while updating neighbours
    at net.minecraft.world.World.func_190524_a(World.java:572) ~[amu.class:?]
    at net.minecraft.world.World.func_175685_c(World.java:496) ~[amu.class:?]
    at net.minecraft.world.World.func_175722_b(World.java:440) ~[amu.class:?]
    at net.minecraft.world.World.markAndNotifyBlock(World.java:381) ~[amu.class:?]
    at net.minecraft.world.World.func_180501_a(World.java:361) ~[amu.class:?]
    at net.minecraft.block.BlockButton.func_180639_a(BlockButton.java:168) ~[apd.class:?]
    at net.minecraft.server.management.PlayerInteractionManager.func_187251_a(PlayerInteractionManager.java:449) ~[or.class:?]
    at net.minecraft.network.NetHandlerPlayServer.func_184337_a(NetHandlerPlayServer.java:741) ~[pa.class:?]
    at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.func_148833_a(SourceFile:55) ~[ma.class:?]
    at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.func_148833_a(SourceFile:11) ~[ma.class:?]
    at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[hv$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_202]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_202]
    at net.minecraft.util.Util.func_181617_a(SourceFile:46) ~[h.class:?]
    ... 5 more
Caused by: java.lang.StackOverflowError
    at vswe.superfactory.components.CommandExecutor.executeCommand(CommandExecutor.java:185) ~[CommandExecutor.class:?]
    at vswe.superfactory.components.CommandExecutor.executeChildCommands(CommandExecutor.java:178) ~[CommandExecutor.class:?]
    at vswe.superfactory.components.CommandExecutor.executeTriggerCommand(CommandExecutor.java:170) ~[CommandExecutor.class:?]
    at vswe.superfactory.tiles.TileEntityManager.activateTrigger(TileEntityManager.java:290) ~[TileEntityManager.class:?]
    at vswe.superfactory.components.TriggerHelper.activateTrigger(TriggerHelper.java:167) ~[TriggerHelper.class:?]
    at vswe.superfactory.components.TriggerHelperRedstone.onRedstoneTrigger(TriggerHelperRedstone.java:64) ~[TriggerHelperRedstone.class:?]
    at vswe.superfactory.tiles.TileEntityManager.triggerRedstone(TileEntityManager.java:297) ~[TileEntityManager.class:?]
    at vswe.superfactory.tiles.TileEntityInput.lambda$triggerRedstone$0(TileEntityInput.java:44) ~[TileEntityInput.class:?]
    at java.util.ArrayList.forEach(Unknown Source) ~[?:1.8.0_202]
    at vswe.superfactory.tiles.TileEntityInput.triggerRedstone(TileEntityInput.java:44) ~[TileEntityInput.class:?]
    at vswe.superfactory.blocks.BlockCableInput.updateRedstone(BlockCableInput.java:80) ~[BlockCableInput.class:?]
    at vswe.superfactory.blocks.BlockCableInput.getWeakChanges(BlockCableInput.java:73) ~[BlockCableInput.class:?]
    at net.minecraft.world.World.func_175666_e(World.java:3818) ~[amu.class:?]
    at net.minecraft.tileentity.TileEntity.func_70296_d(TileEntity.java:163) ~[avj.class:?]
    at net.minecraft.tileentity.TileEntityLockableLoot.func_70299_a(TileEntityLockableLoot.java:139) ~[awa.class:?]
    at net.minecraftforge.items.wrapper.InvWrapper.insertItem(InvWrapper.java:100) ~[InvWrapper.class:?]
    at vswe.superfactory.components.CommandExecutor.insertItemsFromInputBufferElement(CommandExecutor.java:627) ~[CommandExecutor.class:?]
    at vswe.superfactory.components.CommandExecutor.insertItems(CommandExecutor.java:574) ~[CommandExecutor.class:?]
    at vswe.superfactory.components.CommandExecutor.executeCommand(CommandExecutor.java:203) ~[CommandExecutor.class:?]
    at vswe.superfactory.components.CommandExecutor.executeChildCommands(CommandExecutor.java:178) ~[CommandExecutor.class:?]
    [...]

Last two lines are the first two of the next repeating block, which continues up till the 1024 stack limit

TeamDman commented 5 years ago

Almost couldn't reproduce, but I had the output chests reversed. The chests must be facing south, with the items going from the southmost chest into the western chest. image Working on a fix now

TeamDman commented 5 years ago

image In depth analysis: Pressing a button causes a neighborChanged, calls triggerRedstone, calls a command executor, moves items into the chest, chest marked dirty, chest comparator output recalculation, getWeakChanges called on the redstone input, calls triggerRedstone, loop

For now, I'm going to look into removing the listener for the getWeakChanges method that's called when the chest's comparator level is updated. If the redstone still works properly, then that should be the fix.

Not sure why the items are duplicating, the second iteration of the loop should see that the items are already moved, hopefully fixing the redstone loop fixes that

TeamDman commented 5 years ago

image Looks fixed, pushing a build now.

Thanks for the report!

TeamDman commented 5 years ago

Pushed, waiting approval https://minecraft.curseforge.com/projects/super-factory-manager/files/2707558