JoXW100 / TehsStardewValleyMods

A collection of mods for Stardew Valley
MIT License
4 stars 0 forks source link

Reference to Null in FishingRodPatcher.cs #4

Open above-c-level opened 3 months ago

above-c-level commented 3 months ago

@JoXW100 Hey famioli, hope you're doing well

There's an issue within FishingRodPatcher.cs I found with this line: rod.GetTackle().Select(tackle => tackle.ItemId).ToList()

I'm not entirely sure what is going on there honestly, but it appeared to be some kind of null within the lambda of tackle => tackle.ItemId—I haven't worked with C# in a couple years now so my approach is very likely overkill, but this did appear to fix the problem for me:

IEnumerable<string>? rodTackleSelected = null;
rodTackleSelected = rodTackle?.Where(tackle => tackle != null && tackle.ItemId != null)
    .Select(tackle => tackle.ItemId);
var rodTackleList = rodTackleSelected?.ToList();
var customBobber = this.customBobberBarFactory.Create(
    fishingInfo,
    fishEntry,
    fishItem,
    fishSizePercent,
    treasure,
    rodTackleList ?? new List<string>(),
    fromFishPond
);

I tried simply wrapping it in a try/catch block but that didn't seem to fix the issue, resulting in the above workaround. When printing the fishEntry.FishKey, the key that was given appeared to correspond to a sea cucumber in one test I did??? It definitely said something about object 154. I know the above isn't a ton to go off of for repro steps, but maybe you'll see something that'll help you out, before the above fix I would frequently get an upside down and reversed "HIT" indicator, along with a ton of thrown exceptions An error occurred in the base update loop: NullReferenceException: Object reference not set to an instance of an object. and line 192 being the source of the thrown exception.

This may potentially be directly related to #2, the error message certainly matches up. Normally I'd just make a pull request, but I'm not particularly satisfied with the quality of the code mentioned above and would ideally work something out that is more elegant and patches the root issue, rather than just throwing a lot of things at it hoping one sticks. Feel free to modify it or use as-is as you wish, though.

JoXW100 commented 2 months ago

Good find, i have been busy for the last week and not had time to look at the issues with this mod. During the weekend i will see if i have time for a proper rewrite of the code as currently many features are completely broken. If i don't rewrite the mod i will try to patch this issue.