ChrisNZL / Tallowmere2

Changelog, issue tracker, and development knowledge for Tallowmere 2.
https://tallowmere2.com
13 stars 0 forks source link

Possible refactor: Replace instances of Dictionary with ConcurrentDictionary #1074

Closed ChrisNZL closed 1 year ago

ChrisNZL commented 2 years ago

Dictionary is not thread-safe.

Despite the game not using async stuff (apart from minion AI which is not enabled publicly anywhere), Unity or Mono still causes occasional rare IndexOutOfRangeExceptions when trying to merely Add an entry to a Dictionary, even though the game is supposed to be thread-safe.

ConcurrentDictionary is thread-safe, but does not offer the same method APIs as Dictionary.

I am wondering if switching to ConcurrentDictionary in the code (400+ instances of it) would help. Could implement some extension methods to mimic the Dictionary.Add calls. But not sure this is worth refactoring.

ChrisNZL commented 1 year ago

Can't be bothered...