Revolutionary-Games / Thrive

The main repository for the development of the evolution game Thrive.
https://revolutionarygamesstudio.com/
Other
2.83k stars 501 forks source link

Auto-evo failure in SimulationCache.GetEnergyBalanceForSpecies with NullReferenceException #3004

Open hhyyrylainen opened 2 years ago

hhyyrylainen commented 2 years ago

Reported by a player getting very often auto-evo failures with errors like this:

Auto-evo failed with an exception: System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object) ---> System.NullReferenceException: Object reference not set to an instance of an object
  at AutoEvo.SimulationCache.GetEnergyBalanceForSpecies (MicrobeSpecies species, Patch patch) [0x00009] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at ChunkFoodSource.FitnessScore (Species species, AutoEvo.SimulationCache simulationCache) [0x00019] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.PopulationSimulation.SimulatePatchStep (AutoEvo.SimulationConfiguration simulationConfiguration, Patch patch, System.Collections.Generic.IEnumerable`1[T] genericSpecies, System.Random random, AutoEvo.SimulationCache cache, AutoEvoConfiguration autoEvoConfiguration) [0x00196] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.PopulationSimulation.RunSimulationStep (AutoEvo.SimulationConfiguration parameters, System.Collections.Generic.List`1[T] species, System.Collections.Generic.IEnumerable`1[T] patchesToSimulate, System.Random random, AutoEvo.SimulationCache cache, AutoEvoConfiguration autoEvoConfiguration) [0x00057] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.PopulationSimulation.Simulate (AutoEvo.SimulationConfiguration parameters) [0x00080] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.FindBestMigration.TryCurrentVariant () [0x0001f] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.VariantTryingStep.RunStep (AutoEvo.RunResults results) [0x0000a] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvoRun.RunSingleStepToCompletion (AutoEvo.IRunStep step) [0x00008] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvoRun+<>c__DisplayClass55_0.<Step>b__1 () [0x00000] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in <1400ea11d6fd49d4939be686a9549fb4>:0 
  at System.Threading.Tasks.Task.Execute () [0x00000] in <1400ea11d6fd49d4939be686a9549fb4>:0 
   --- End of inner exception stack trace ---
  at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <1400ea11d6fd49d4939be686a9549fb4>:0 
  at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00043] in <1400ea11d6fd49d4939be686a9549fb4>:0 
  at System.Threading.Tasks.Task.Wait () [0x00000] in <1400ea11d6fd49d4939be686a9549fb4>:0 
  at TaskExecutor.RunTasks (System.Collections.Generic.IEnumerable`1[T] tasks, System.Boolean runExtraTasksOnCallingThread) [0x0009e] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvoRun.Step () [0x0011c] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvoRun.Run () [0x00018] in <a4ccd80a610a4c1eac57bb911b092060>:0 
---> (Inner Exception #0) System.NullReferenceException: Object reference not set to an instance of an object
  at AutoEvo.SimulationCache.GetEnergyBalanceForSpecies (MicrobeSpecies species, Patch patch) [0x00009] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at ChunkFoodSource.FitnessScore (Species species, AutoEvo.SimulationCache simulationCache) [0x00019] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.PopulationSimulation.SimulatePatchStep (AutoEvo.SimulationConfiguration simulationConfiguration, Patch patch, System.Collections.Generic.IEnumerable`1[T] genericSpecies, System.Random random, AutoEvo.SimulationCache cache, AutoEvoConfiguration autoEvoConfiguration) [0x00196] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.PopulationSimulation.RunSimulationStep (AutoEvo.SimulationConfiguration parameters, System.Collections.Generic.List`1[T] species, System.Collections.Generic.IEnumerable`1[T] patchesToSimulate, System.Random random, AutoEvo.SimulationCache cache, AutoEvoConfiguration autoEvoConfiguration) [0x00057] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.PopulationSimulation.Simulate (AutoEvo.SimulationConfiguration parameters) [0x00080] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.FindBestMigration.TryCurrentVariant () [0x0001f] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvo.VariantTryingStep.RunStep (AutoEvo.RunResults results) [0x0000a] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvoRun.RunSingleStepToCompletion (AutoEvo.IRunStep step) [0x00008] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at AutoEvoRun+<>c__DisplayClass55_0.<Step>b__1 () [0x00000] in <a4ccd80a610a4c1eac57bb911b092060>:0 
  at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in <1400ea11d6fd49d4939be686a9549fb4>:0 
  at System.Threading.Tasks.Task.Execute () [0x00000] in <1400ea11d6fd49d4939be686a9549fb4>:0 <---

Here's the function that is listed last in the callstack:

https://github.com/Revolutionary-Games/Thrive/blob/87dfcad0fb3e1a013ac3874c5e5da8921f0657c6/src/auto-evo/simulation/SimulationCache.cs#L18

Which is pretty simple so really it looks like the only thing that could really be null is species, patch or cachedEnergyBalances.

hhyyrylainen commented 2 years ago

Looking at the logs this seems to happen in the editor, meaning that this is a sibling issue of: https://github.com/Revolutionary-Games/Thrive/issues/3006

I would guess that there is a small chance that the microbe object was just being modified causing the data to be null and hitting this error. As mentioned in that other issue I already added some mitigation, but this too probably should be fully fixed by a solution to that issue #3006

hhyyrylainen commented 2 years ago

Actually reading through the logs again, that doesn't seem to be the case actually because those errors appeared before the microbe editor time elapse message was printed, meaning that the error did come from a normal auto-evo run. It seems the player maybe had auto-evo during gameplay turned off, but even with that I can't get this error to happen, the most I can do is add some extra checking code to try to find where that null comes from sometime in the future when this issue gets reported again.