Skip to content

Commit

Permalink
Fix exception on resource middle click in NEIE
Browse files Browse the repository at this point in the history
In the Never Enough Items, middle click on a resource. This
will navigate to the clicked resource, but also crashed the current Build process, because of modification of the
iterated list.
  • Loading branch information
exyi committed Jun 4, 2024
1 parent 9df2f7f commit 3346222
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
30 changes: 17 additions & 13 deletions Yafc/Windows/NeverEnoughItemsPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Yafc.Model;
using Yafc.UI;

Expand Down Expand Up @@ -57,8 +58,8 @@ public RecipeEntry(Recipe recipe, bool isProduction, Goods currentItem, bool atC
}
}

private readonly List<RecipeEntry> productions = [];
private readonly List<RecipeEntry> usages = [];
private RecipeEntry[] productions = [];
private RecipeEntry[] usages = [];

private NeverEnoughItemsPanel() : base(76f) {
productionList = new ScrollArea(40f, BuildItemProduction, new Padding(0.5f));
Expand Down Expand Up @@ -89,20 +90,23 @@ private void SetItem(Goods current) {
recent.Add(this.current);
}

this.current = current;
currentFlow = current.ApproximateFlow(atCurrentMilestones);
productions.Clear();
foreach (var recipe in current.production) {
productions.Add(new RecipeEntry(recipe, true, current, atCurrentMilestones));
var productions = new RecipeEntry[current.production.Length];
for (int i = 0; i < current.production.Length; i++) {
productions[i] = new RecipeEntry(current.production[i], true, current, atCurrentMilestones);
}
Array.Sort(productions, this);

productions.Sort(this);
usages.Clear();
foreach (var usage in current.usages) {
usages.Add(new RecipeEntry(usage, false, current, atCurrentMilestones));
var usages = new RecipeEntry[current.usages.Length];
for (int i = 0; i < current.usages.Length; i++) {
usages[i] = new RecipeEntry(current.usages[i], false, current, atCurrentMilestones);
}
Array.Sort(usages, this);

this.current = current;
this.productions = productions;
this.usages = usages;

usages.Sort(this);
Rebuild();
productionList.Rebuild();
usageList.Rebuild();
Expand Down Expand Up @@ -268,7 +272,7 @@ private void ChangeShowStatus(EntryStatus status) {
usageList.Rebuild();
}

private void DrawEntryList(ImGui gui, List<RecipeEntry> entries, bool production) {
private void DrawEntryList(ImGui gui, ReadOnlySpan<RecipeEntry> entries, bool production) {
bool footerDrawn = false;
var prevEntryStatus = EntryStatus.Normal;
FactorioObject? prevLatestMilestone = null;
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version: 0.7.1
Date: soon
Fixes:
- Display spent fuel items in the production table and link summaries.
- Fix error when switching items in NEIE with middle-click
----------------------------------------------------------------------------------------------------------------------
Version: 0.7.0
Date: May 25th 2024
Expand Down

0 comments on commit 3346222

Please sign in to comment.