Repository navigation
Clamp crafting plan scroll position to the element count - #242
Closed
PeanutSplash wants to merge 1 commit into
Closed
PeanutSplash wants to merge 1 commit into
PeanutSplash wants to merge 1 commit into
Conversation
getVisibleElements() passed firstRow as the start index of subList without clamping it to the (possibly shrunken) element count. When a plan is refreshed with fewer elements than the row the user had scrolled to - which happens as a crafting job progresses - subList threw IllegalArgumentException: fromIndex(74) > toIndex(35) and crashed the client from the render thread. Clamp the start index in the three places that slice a scrollable list (GuiCraftingPlan, ContainerScreenTerminalCraftingJobs, ContainerScreenTerminalStorageCraftingOptionAmount), and clamp the stored first row when the element list is refreshed.
Member
|
Thanks for the PR, but this doesn't look like the right fix to me. The problem is that |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug
Opening the Crafting Jobs terminal, scrolling down in the crafting plan and letting the plan refresh can crash the client:
Happened on
1.20.4-1.4.13in an FTB NeoTech instance (client crash, render thread).Cause
getVisibleElements()only clamps the end index:firstRowitself is never clamped, andsetFirstRow()only guaranteesfirstRow >= 0.When the plan is refreshed through
inheritVisualizationState()->refreshList()and the element list became shorter than the row the user had scrolled to (a crafting job progressing naturally removes steps),firstRowends up past the end of the list andsubListthrows.Two other places slice a scrollable list the same way and can hit the same exception:
ContainerScreenTerminalCraftingJobs#getVisiblePlans()ContainerScreenTerminalStorageCraftingOptionAmount#drawOutputSlots()Fix
firstRowcan never exceed the list length.firstRowinGuiCraftingPlan#refreshList()so the scroll state stays consistent after the list shrinks (prevents the view from jumping back to the wrong row on the next scroll).No behaviour change for valid scroll positions.
Notes
master-1.21*,master-1.20), so this may be worth backporting - let me know if you want me to open those PRs instead/too.List.subList); the crash no longer reproduces when scrolling a plan that shrinks../gradlew buildhere, as the change is limited to index clamping.