Race Condition I found

I had a Race Condition that was causing a memory leak, lol. It took me awhile to figure out that a race condition was the culprit, but basically, BaseStats.GetStat() (with the stat additives) was getting called before Fighter class had a chance to call it’s Start() method to initialize it’s current weapon, so it was trying to get info from a null weapon value and the whole game was crashing. So, I just added an extra method to ensure that the default values (default weapon, default base stats based on level, ect) get set, and in addition to calling that from start I’m also calling it in any place where I expect those things to already be established, just as a safety-net. Now everything is fine!

Assigning the weapon in Awake() will always ensure it’s done before BaseStats calls GetStat() (unless you’ve got something calling BaseStats before Awake()). We’ll be using LazyValue very soon to help mitigate some of these race conditions.

Privacy & Terms