From dc196b8993a609eaa40a7a1f1d27f27e014cca28 Mon Sep 17 00:00:00 2001 From: score Date: Sat, 30 Jan 2021 21:16:28 +0000 Subject: [PATCH] Crash #2811 fix (#2812) * Use mutable list to allow updates even when grid is inactive I don't think this should happen but it does, so this makes it continue silently instead of crashing. Fix refinedmods/refinedstorage#2811 * Do not show updated items if there is no full inventory yet * Ensure gridview list implementation is ArrayList The update code relies on an indexed mutable list, so that should be made explicit here. --- .../refinedstorage/screen/grid/view/GridViewImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/GridViewImpl.java b/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/GridViewImpl.java index 1e84ef6c8..f8cf0a345 100644 --- a/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/GridViewImpl.java +++ b/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/GridViewImpl.java @@ -16,6 +16,7 @@ import java.util.stream.Stream; public class GridViewImpl implements IGridView { private final GridScreen screen; private boolean canCraft; + private boolean active = false; private final IGridSorter defaultSorter; private final List sorters; @@ -55,9 +56,11 @@ public class GridViewImpl implements IGridView { this.stacks = map.values().stream() .filter(getActiveFilters()) .sorted(getActiveSort()) - .collect(Collectors.toList()); + .collect(Collectors.toCollection(ArrayList::new)); + this.active = true; } else { - this.stacks = Collections.emptyList(); + this.stacks = new ArrayList<>(); + this.active = false; } this.screen.updateScrollbar(); @@ -111,6 +114,9 @@ public class GridViewImpl implements IGridView { @Override public void postChange(IGridStack stack, int delta) { + if (!this.active) { + return; + } // COMMENT 1 (about this if check in general) // Update the other id reference if needed. // Taking a stack out - and then re-inserting it - gives the new stack a new ID