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

[Fix] Item Overflowing #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JustAHuman-xD
Copy link
Collaborator

@JustAHuman-xD JustAHuman-xD commented Oct 24, 2024

Yesterday a player on MetaMechanists reported their grid showing their cobblestone in the negative billions, indicating the display had overflown (not the actual amount as they could still withdraw items), so today I worked on fixing the bug.

First I re-did the NetworkRoot#getAllNetworkItems method to use NumberUtils#flowSafeAddition instead of the manual method using longs being used, also just cleaning up the method by using Map#compute, when that didn't fix it (which I didn't expect it to but did it regardless) I did a little more debugging and found the problem was actually that the BarrelIdentity#getAmount had already overflowed, so I tracked it down to be the NetworkRoot#getNetworkStorage and NetworkRoot#getInfinityBarrel methods, both add the stored amount and the amount in the output slot, so if either have a stored amount of integer max when you add the output amount it overflows. After finding that out I just made it use flow safe addition and also moved around a couple of guard statements to avoid unnecessary logic. Afterwards I noticed that in a lot of places there was a call to StackUtils#getAsQuantity(itemStack, 1) and in some spots there was just a replication of that logic (itemStack.clone(), clone.setAmount(1), so I added a method overload, StackUtils#getAsOne and replaced the usages and logic replications with it.

After testing in game with a infinite quantum storage and a 4k quantum storage both full with cobble completely and inputs and output slots filled, before these changes it overflows, after these changes it does not 👍

- Redo NetworkRoot#getAllNetworkItems
- Add flow safety to NetworkRoot#getNetworkStorage
- Add flow safety to NetworkRoot#getInfinityBarrel
- Add StackUtils#getAsOne
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

Successfully merging this pull request may close these issues.

1 participant