-
Notifications
You must be signed in to change notification settings - Fork 50
Patches for various crashes #781
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/mod/acgaming/universaltweaks/mods/ae2uel/mixin/UTItemHandlerIteratorMixin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package mod.acgaming.universaltweaks.mods.ae2uel.mixin; | ||
|
|
||
| import net.minecraft.item.ItemStack; | ||
|
|
||
| import appeng.util.inv.ItemHandlerIterator; | ||
| import appeng.util.inv.ItemSlot; | ||
| import org.spongepowered.asm.mixin.Final; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
|
||
| @Mixin(value = ItemHandlerIterator.class, remap = false) | ||
| public class UTItemHandlerIteratorMixin { | ||
|
|
||
| @Shadow | ||
| @Final | ||
| private ItemSlot itemSlot; | ||
|
|
||
| @Shadow | ||
| private int slot; | ||
|
|
||
| /// As far as I can tell, this crash happens when the IItemHandler that's being iterated over changes its | ||
| /// length in the middle of being iterated over. This is obviously a bug, but AE2 has no control over how the | ||
| /// IItemHandler behaves. This mixin changes the behaviour of ItemHandlerIterator to instead pretend these | ||
| /// invalid slots are empty and cannot be extracted from, instead of crashing. | ||
| /// | ||
| /// java.util.NoSuchElementException | ||
| /// at appeng.util.inv.ItemHandlerIterator.next(ItemHandlerIterator.java:48) | ||
| /// at appeng.util.inv.ItemHandlerIterator.next(ItemHandlerIterator.java:28) | ||
| /// at appeng.parts.misc.ItemHandlerAdapter$InventoryCache.update(ItemHandlerAdapter.java:272) | ||
| /// at appeng.parts.misc.ItemHandlerAdapter.onTick(ItemHandlerAdapter.java:201) | ||
| /// at appeng.parts.misc.PartStorageBus.tickingRequest(PartStorageBus.java:316) | ||
| /// at appeng.me.cache.TickManagerCache.onUpdateTick(TickManagerCache.java:91) | ||
| /// at appeng.me.GridCacheWrapper.onUpdateTick(GridCacheWrapper.java:40) | ||
| /// at appeng.me.Grid.update(Grid.java:229) | ||
| /// at appeng.hooks.TickHandler.onTick(TickHandler.java:196) | ||
| /// at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:78) | ||
| /// at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:212) | ||
| /// at net.minecraftforge.fml.common.FMLCommonHandler.onPostServerTick(FMLCommonHandler.java:277) | ||
| /// at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:712) | ||
| /// at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:185) | ||
| /// at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526) | ||
| /// at java.lang.Thread.run(Thread.java:1474) | ||
| @Inject(method = "next()Lappeng/util/inv/ItemSlot;", at = @At(value = "NEW", target = "()Ljava/util/NoSuchElementException;"), cancellable = true) | ||
| private void ut$preventNSEE(CallbackInfoReturnable<ItemSlot> cir) { | ||
| ((UTItemSlotAccessor) this.itemSlot).ut$setExtractable(false); | ||
| this.itemSlot.setItemStack(ItemStack.EMPTY); | ||
| this.itemSlot.setSlot(this.slot); | ||
| ++this.slot; | ||
| cir.setReturnValue(this.itemSlot); | ||
| } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
src/main/java/mod/acgaming/universaltweaks/mods/ae2uel/mixin/UTItemSlotAccessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package mod.acgaming.universaltweaks.mods.ae2uel.mixin; | ||
|
|
||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
|
||
| import appeng.util.inv.ItemSlot; | ||
|
|
||
| @Mixin(value = ItemSlot.class, remap = false) | ||
| public interface UTItemSlotAccessor { | ||
|
|
||
| @Invoker("setExtractable") | ||
| void ut$setExtractable(boolean isExtractable); | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think throwing an
NoSuchElementExceptionis the correct behavior here, and the issue lies with whatever is having variable item slots between calls. to debug the cause, i would suggest doing@WrapMethodwith atry { original() } catchfor this inPartStorageBus#tickingRequestand logging the position it happened to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'd usually agree with you, this crash is very hard to reproduce and I'm not even sure what the actual cause is. Like I said, I can't be bothered to restart my game a few dozen times to test it. This is absolutely a hack but there's no reason that a misbehaving IItemHandler should crash the game.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to add this: an IItemHandler reporting more slots than it has is absolutely a bug, but there's no logic error from pretending those slots exist but aren't interactable. This iterator is just used for determining what items an IItemHandler contains, so at most you're going to get false-negatives (items in storage that aren't reported to AE). Assuming the IItemHandler eventually corrects itself, this isn't even permanent because storage busses poll their attached inventories constantly.