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 node insert crash #328

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LilyRose2798
Copy link

@LilyRose2798 LilyRose2798 commented Jan 20, 2025

I have discovered a crash relating to inserting cards into a laserio node and decided to investigate and find a resolution for the issue.

The issue is that if you insert cards into a laserio node using any form of item transfer (either hopper, other mods, or using laserio itself), then the node will allow all 25 slots of its inventory (minus the one overclocker slot) to be filled with cards. To recreate just put a hopper/chute/etc on top of a node, and put 10 item cards in it.
Only the player should be allowed to insert into the cardholder slots of a node, not a machine, so to prevent this I edited the LaserNodeItemHandler::isItemValid method to disallow cards from being inserted into slots 9-25. This does not prevent players from interacting with the card holder slots themselves, just from cards being transferred by other means into those slots of the node.
The other issue that contributed to this crash is that LaserNodeBE::populateRenderList iterates through all 25 slots, not just the 9 card slots. This means that if cards end up in any of the other 15 slots (like through the bug above) that it will call MiscTools::findOffset with a slot parameter greater than 9, causing offsets[slot] to throw an OutOfBoundsException. This is what actually crashes the game. I considered also adding a check to the MiscTools::findOffset function to check that slot is in range of offsets.length, but decided to leave that out. There are other parts of the code that call that function, so it may be worth adding that check in the future to prevent other obscure crashes.

Fixes crash where cardholder slots are populated with cards and are attempted to be rendered
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