Skip to content

Commit

Permalink
Fix an exception when recipe-hovering with a pathological configurati…
Browse files Browse the repository at this point in the history
…on. (#150)

Specifically, an ArgumentOutOfRangeException happens when hovering over
a recipe that is unlocked by a technology that (directly or indirectly)
requires a science pack that is both (a) inaccessible and (b) not a
milestone.

For an example of this in action, load [this vanilla
project](https://github.com/user-attachments/files/15782026/exception.zip)
and hover over either of the two personal roboport recipe icons. Both
will cause an exception, but the steel recipe icon won't. Open the
milestones editor and add Chemical science pack to the milestones.
Alternatively, open the Dependency explorer for the Chemical science
pack item, and click "Clear mark". In both cases, the exceptions will
disappear.
  • Loading branch information
shpaass authored Jun 11, 2024
2 parents 9edb974 + cb652a0 commit d987a4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Yafc.Model/Analysis/TechnologyScienceAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ public class TechnologyScienceAnalysis : Analysis {
public Mapping<Technology, Ingredient[]> allSciencePacks { get; private set; }

public Ingredient? GetMaxTechnologyIngredient(Technology tech) {
var list = allSciencePacks[tech];
Ingredient[] list = allSciencePacks[tech];
Ingredient? ingredient = null;
Bits order = new Bits();
foreach (var entry in list) {
var entryOrder = Milestones.Instance.GetMilestoneResult(entry.goods.id) - 1;
foreach (Ingredient entry in list) {
Bits entryOrder = Milestones.Instance.GetMilestoneResult(entry.goods.id);
if (entryOrder != 0) {
entryOrder -= 1;
}// else: The science pack is not accessible *and* not a milestone. We may still display it, but any actual milestone will win.

if (ingredient == null || entryOrder > order) {
order = entryOrder;
ingredient = entry;
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Date: soon
Fixes:
- Display spent fuel items in the production table and link summaries.
- Fix error when switching items in NEIE with middle-click
- Fix an exception when hovering over recipes in certain pathological cases.
----------------------------------------------------------------------------------------------------------------------
Version: 0.7.0
Date: May 25th 2024
Expand Down

0 comments on commit d987a4e

Please sign in to comment.