Skip to content

Commit

Permalink
Fix: Add nullcheck for linkedGoods (ShadowTheAge#193)
Browse files Browse the repository at this point in the history
While using YaFC-CE today i ran into an exception because `linkedGoods`
in `summer.TryGetValue(linkedGoods, ...)` was null. This fixed that.

It's kinda a blind fix since i have no steps to reproduce, YaFC was
hanging right after the exception message (i made another issue for
that). But judging the code this should work.
  • Loading branch information
shpaass authored Jul 13, 2024
2 parents 4952ea2 + 0adab5e commit a459a39
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Yafc.Model/Model/ProductionTable.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -183,9 +184,14 @@ private static void AddFlow(RecipeRow recipe, Dictionary<Goods, (double prod, do
for (int i = 0; i < recipe.recipe.ingredients.Length; i++) {
var ingredient = recipe.recipe.ingredients[i];
var linkedGoods = recipe.links.ingredientGoods[i];
_ = summer.TryGetValue(linkedGoods, out var prev);
prev.cons += recipe.recipesPerSecond * ingredient.amount;
summer[linkedGoods] = prev;
if (linkedGoods is not null) {
_ = summer.TryGetValue(linkedGoods, out var prev);
prev.cons += recipe.recipesPerSecond * ingredient.amount;
summer[linkedGoods] = prev;
}
else {
Debug.WriteLine("linkedGoods should not have been null here.");
}
}

if (recipe.fuel != null && !float.IsNaN(recipe.parameters.fuelUsagePerSecondPerBuilding)) {
Expand Down

0 comments on commit a459a39

Please # to comment.