Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add nullcheck for linkedGoods #193

Merged
merged 2 commits into from
Jul 13, 2024

Conversation

Dorus
Copy link
Collaborator

@Dorus Dorus commented Jul 13, 2024

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.

@shpaass
Copy link
Owner

shpaass commented Jul 13, 2024

Any idea why linkedGoods was null? It's doesn't happen often because otherwise we would've encountered it earlier, so I am curious.

@Dorus
Copy link
Collaborator Author

Dorus commented Jul 13, 2024

I'm unable to say, i was clicking around and adding a lot of recipes, changing fuels, changing links etc. Using both left click, right click, ctr+click. And i have a memory of a frog sometimes so i couldn't reproduce it.

@shpaass
Copy link
Owner

shpaass commented Jul 13, 2024

As we don't know the reason behind the linkedGoods being null, I suggest to add a logger in addition to the current changes. Let it write all relevant info to the file and show a warning similar to the error message when in the debug mode. This way, you or other devs will eventually collect enough info to understand the reason behind the error.

@Dorus
Copy link
Collaborator Author

Dorus commented Jul 13, 2024

It seems to be an issue that YaFC is running multiple threads, and sometimes modifications are made to the items it is already iterating over.

afbeelding

(This also returned the previous mentioned freeze in #192)

I just got a similar but different error than last time while trying to reproduce it.

@Dorus
Copy link
Collaborator Author

Dorus commented Jul 13, 2024

Random idea: But did we already run multiple threads like this at or before update 0.7.0?

@Dorus
Copy link
Collaborator Author

Dorus commented Jul 13, 2024

Another update: I got him:
afbeelding
I added a thread.sleep to make it a little easier to trigger, but then if you are iterating this code before linked goods are added, it gets to this. You need to have an empty group, and add a new item to it, remove it, and add it again, and then at an unlucky time:

afbeelding
->
afbeelding
For a brief moment you'll notice the ingredients are missing. These get added a fraction of a second later (but slowly because of my debug thread.sleep). If unlucky, it crashes before these ingredients are actually added.

This happens especially when you add/remove that first sub-recipe a couple times in a row. It helps that i have a very large recipe tab. Still, without the extra sleep i cannot reproduce it now, but it is how i got it the first time.

@Dorus
Copy link
Collaborator Author

Dorus commented Jul 13, 2024

As we don't know the reason behind the linkedGoods being null, I suggest to add a logger in addition to the current changes. Let it write all relevant info to the file and show a warning similar to the error message when in the debug mode. This way, you or other devs will eventually collect enough info to understand the reason behind the error.

Eeeh, stupid question, do we log with Debug.WriteLine or Console.Writeline? I dont think we've ever made work of adding ILogger to the system.

@shpaass
Copy link
Owner

shpaass commented Jul 13, 2024

do we log with Debug.WriteLine or Console.Writeline?

My idea was to log both in the console and the file.
Regarding your question, I'm not sure which option is correct. We need to check what logging approach is present and see if we want to keep or change it.

@Dorus
Copy link
Collaborator Author

Dorus commented Jul 13, 2024

Also, i've verified my fix works, do we still need the log line?

I can put it on my list to give the logger a swing, but i got at most an hour tomorrow to hack away at it so idk if i can get anything done in that department.

@shpaass
Copy link
Owner

shpaass commented Jul 13, 2024

I suggest to add at least the logging that you mentioned in your prevoius message, with the comment that this type of logging is not set in stone.

@Dorus
Copy link
Collaborator Author

Dorus commented Jul 13, 2024

Done 👍

@shpaass shpaass merged commit a459a39 into shpaass:master Jul 13, 2024
1 check passed
@Dorus Dorus deleted the linkedGoodsNullcheck branch July 13, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants