Skip to content

Fix crash when a scrolled crafting job plan with collapsed rows refreshes - #243

Merged
rubensworks merged 1 commit into
master-1.20-ltsfrom
claude/inspiring-fermat-vvaq8d
Nov 16, 2026
Merged

rubensworks merged 1 commit into
master-1.20-ltsfrom
claude/inspiring-fermat-vvaq8d

Conversation

@rubensworks

@rubensworks rubensworks commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Alternative to #242, targeting the lowest maintained branch so it can be upmerged.

Cause

The live crafting job plan (ContainerScreenTerminalCraftingJobsPlan) rebuilds its GuiCraftingPlan on every server update (every second by default) and calls inheritVisualizationState on it. That method applied the previous scroll position before re-hiding the previously collapsed elements:

  1. The new view starts with all elements visible, so scrollTo(f) sets firstRow = round(f * (allElements - visibleRows)).
  2. Collapsed elements are then hidden and refreshList() shrinks the list. WidgetScrollBar#setTotalRows does not re-run the scroll callback, so firstRow keeps the value computed for the full list.

If firstRow ends up past the end of the visible list, getVisibleElements() crashes the client with IllegalArgumentException: fromIndex(x) > toIndex(y). Below that threshold there is no crash, but the plan jumps to the wrong (partly empty) rows on every refresh.

The trigger is collapsing rows and then scrolling. A plan that shrinks while scrolled does not cause this, as #242 suggests, because the new view's scrollbar is sized to the new plan.

Fix

Restore the collapsed state and refresh the visible list first, then apply the scroll position.

#242 also changes ContainerScreenTerminalCraftingJobs#getVisiblePlans() and ContainerScreenTerminalStorageCraftingOptionAmount#drawOutputSlots(). Neither can hit this exception, so this PR leaves them alone:

  • The crafting jobs overview never registers its scrollbar as a widget and has no mouseScrolled handler, so firstRow is always 0 there. Wheel, drag and click on the scrollbar all leave it at 0, confirmed in a dev client. That is a separate bug: jobs after the 10th can't be reached.
  • The outputs list of the crafting amount screen is final and never changes after construction.

Testing

  • Reproduced on master-26-lts (same code) in a dev client driven by clientdevbridge. I used a running job with 54 plan rows, collapsed one branch (37 visible rows), scrolled to the bottom and waited for the next plan update. The client crashed with fromIndex(44) > toIndex(37) in GuiCraftingPlan.getVisibleElements, where 44 = 54 - 10. With this change, the same steps keep showing the same rows across updates, with no crash.
  • ./gradlew build passes on this branch. There are no game tests on 1.20.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UeSuG89xJRXxfor1cEVHSW

…shes

When the live crafting job plan was refreshed, the scroll position of the
previous view was applied before its collapsed elements were hidden again.
The first row was therefore calculated for the fully expanded list, and
could point past the end of the visible list, which crashed the client
with an IllegalArgumentException from List#subList while rendering.
Below that point, the plan jumped to the wrong rows on every refresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UeSuG89xJRXxfor1cEVHSW
@rubensworks
rubensworks force-pushed the claude/inspiring-fermat-vvaq8d branch from cd69862 to 93e20e9 Compare November 16, 2026 15:30
@rubensworks
rubensworks merged commit 0087123 into master-1.20-lts Nov 16, 2026
3 checks passed
@rubensworks
rubensworks deleted the claude/inspiring-fermat-vvaq8d branch November 16, 2026 15:32
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.

2 participants