View Issue Details

IDProjectCategoryLast Update
0025715AI War 2Crash/ExceptionNov 3, 2021 9:57 pm
ReporterBadgerBadger Assigned ToChris_McElligottPark  
Status resolvedResolutionfixed 
Product VersionBeta 3.742 "Classic Map" For DLC1 
Fixed in VersionBeta 3.744 Pathfinding 
Summary0025715: Relentless wave pathfinder exception
DescriptionThis hit on the most recent svn; from the patch that starts


    Add some variants to the Dissonance map.
    

10/29/2021 6:27:32 PM 3.741 SINGLEP DELAYED6: Called Relentless AI Wave_facplan pathfinder from two different contexts! First was LRP_AIRelentlessWave_idx_18, new one is LRP_AIRelentlessWave_idx_19
  at System.Environment.get_StackTrace () [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0
  at Arcen.Universal.ArcenDebugging.ArcenDebugLog (System.String Message, Arcen.Universal.Verbosity Verbosity) [0x00012] in /home/arcengames_aiw-ultra/CodeCrossProject/ArcenUniversal/src/UtilityLibraries/ArcenDebugging.cs:258
  at Arcen.AIW2.External.ArcenPathfinder`1[N].FindPathInner (Arcen.Universal.List`1[T] PathToFill, N Origin, N Target, System.Int32 NeedToGetWithinXRangeOfTarget, System.Int32 RequiresNoMoreThanXRangeFromOrigin, System.Boolean DoDebugLog, Arcen.AIW2.Core.ArcenSimContextAnyStatus Context) [0x00000] in <3dd16d06478e4f419ddb70f54c11e83d>:0
  at Arcen.AIW2.External.ArcenPathfinder`1[N].FindPath (Arcen.Universal.List`1[T] PathToFill, N Origin, N Target, System.Int32 NeedToGetWithinXRangeOfTarget, System.Int32 RequiresNoMoreThanXRangeFromOrigin, System.Boolean DoDebugLog, Arcen.AIW2.Core.ArcenSimContextAnyStatus Context) [0x00000] in <3dd16d06478e4f419ddb70f54c11e83d>:0
  at Arcen.AIW2.External.PlanetPathfinder.Arcen.AIW2.Core.IPlanetPathfinder.FindPath (Arcen.Universal.List`1[T] PathToFill, Arcen.AIW2.Core.Planet Origin, Arcen.AIW2.Core.Planet Target, System.Int32 NeedToGetWithinXRangeOfTarget, System.Int32 RequiresNoMoreThanXRangeFromOrigin, System.Boolean DoDebugLog, Arcen.AIW2.Core.ArcenSimContextAnyStatus Context) [0x00000] in <3dd16d06478e4f419ddb70f54c11e83d>:0
  at Arcen.AIW2.External.PathingHelper.InnerFindPath_Raw (Arcen.AIW2.Core.Faction faction, Arcen.AIW2.Core.Planet Origin, Arcen.AIW2.Core.Planet Target, Arcen.AIW2.Core.PathingMode mode, Arcen.AIW2.Core.ArcenSimContextAnyStatus Context) [0x00000] in <3dd16d06478e4f419ddb70f54c11e83d>:0
  at Arcen.AIW2.External.SimPlannerImplementation.InnerFindPath_Raw (Arcen.AIW2.Core.Faction faction, Arcen.AIW2.Core.Planet Origin, Arcen.AIW2.Core.Planet Target, Arcen.AIW2.Core.PathingMode mode, Arcen.AIW2.Core.ArcenSimContextAnyStatus Context) [0x00000] in <3dd16d06478e4f419ddb70f54c11e83d>:0
  at Arcen.AIW2.Core.ExternalFactionBaseInfo.FindPathFreshOrFromCache (Arcen.AIW2.Core.Planet Origin, Arcen.AIW2.Core.Planet Target, Arcen.AIW2.Core.PathingMode mode, Arcen.AIW2.Core.ArcenSimContextAnyStatus Context) [0x00039] in /home/arcengames_aiw-ultra/CodeMain/ArcenAIW2Core/src/Logic/Tables/ExternalDataAndCodeLinks/ExternalFactionBaseInfo.cs:450
  at Arcen.AIW2.Core.Faction.FindPathFreshOrFromCache (Arcen.AIW2.Core.Planet origin, Arcen.AIW2.Core.Planet destination, Arcen.AIW2.Core.PathingMode mode, Arcen.AIW2.Core.ArcenSimContextAnyStatus Context) [0x0000c] in /home/arcengames_aiw-ultra/CodeMain/ArcenAIW2Core/src/Logic/GameState/Faction/Faction.cs:5526
  at Arcen.AIW2.External.AIRelentlessAndBorderAggressionFactionDeepInfoRoot.AttackTargetPlanet (Arcen.AIW2.Core.Planet start, Arcen.AIW2.Core.Planet destination, Arcen.Universal.List`1[T] ships, Arcen.AIW2.Core.Faction faction, Arcen.AIW2.External.ArcenLongTermIntermittentPlanningContext Context) [0x00000] in <cb4cc98e45654ba09b28d409dfcdf9ff>:0
  at Arcen.AIW2.External.AIRelentlessAndBorderAggressionFactionDeepInfoRoot+<DoLongRangePlanning_OnBackgroundNonSimThread_Subclass>c__AnonStorey1.<>m__1 (Arcen.Universal.KeyValuePair`2[TKey,TValue] pair) [0x00000] in <cb4cc98e45654ba09b28d409dfcdf9ff>:0
  at Arcen.Universal.DictionaryOfLists`2[TKey,TValue].DoFor (Arcen.Universal.DictionaryProcessor`2[TKey,TValue] Processor) [0x00029] in /home/arcengames_aiw-ultra/CodeCrossProject/ArcenUniversal/src/ArcenCollections/Compound/DictionaryOfLists.cs:147
  at Arcen.AIW2.External.AIRelentlessAndBorderAggressionFactionDeepInfoRoot.DoLongRangePlanning_OnBackgroundNonSimThread_Subclass (Arcen.AIW2.External.ArcenLongTermIntermittentPlanningContext Context) [0x00000] in <cb4cc98e45654ba09b28d409dfcdf9ff>:0
TagsNo tags attached.

Relationships

related to 0025752 resolvedChris_McElligottPark Called ... pathfinder from two different contexts! 

Activities

Chris_McElligottPark

Nov 3, 2021 9:57 pm

administrator   ~0063176

Thanks!

* Added a new ThreadStaticWrapperedPooledItem, which is a way for us to keep some sort of complex object -- often a collection, but more things than that are planned -- in a threadstatic, safe way.
** ...What?
*** Okay, so ThreadStatic. Basically, any time a new thread is using that variable, it can initialize its own copy. This is hyper useful.
*** However, with random background worker threads, this does mean that we wind up with some things initialized on threads that may never be used the same way again.
**** I'm referring here to things like Task<>.Run() or things that happen inside Parallel.For() or similar. Or older-school ThreadPool calls, whatever.
*** Additionally, we pool and reuse our own threads between loads of the game (meaning out to the main menu and back), for things like factions.
**** So if thread 554 was Dark Spire in one game, and you go to the main menu and come back into the same game, it might wind up being the AI Hunter thread instead.
*** Essentially this works vaguely like a memory leak, even though it is in no way a memory leak, because we wind up with stuff that has been allocated but will never be used again.
**** During our "before mapgen or savegame load clear," it makes more sense to recall all the threadstatic stuff, and pull those into central pools, and then start over fresh using them again.
** How we do exactly that is... with this new class, ThreadStaticWrapperedPooledItem!
*** This wrapper item is instead now the thing that is threadstatic, and it communicates under the hood with a pool.
*** We can put anything in here. Collections, pathfinders, and so on.
**** A side benefit of this is that for things where we previous had a scope that was a "context" (that can be VERY confusing), the scope can instead be the thread.
**** Recently, we've been having some issues with pathfinders being called from more than one contextual location at a time, which might have been a false alarm or might have been a very dangerous bug. Either way, this will fix that.
***** But even more to the point, we might have been having some pathfinder bugs if people ever decided to use one from a given context in a Task or Parallel call. I don't think anyone was doing that yet, but if they did it would have given scrambled results.
*** A side effect of these changes is that we can allocate fewer lists and pathfinders in general, because not every faction needs them in the first place. And what we do allocate can get much more reuse.
** If we felt like we needed to, we could extend this concept further and push kind of a library "check in, check out" sort of data structure that keeps things for less long than between map-generations.
*** That said, I think that there is potentially performance loss from that, and I don't expect the RAM usage of my current approach to be enough of a problem to warrant that extra CPU usage.
*** If I get proved wrong later, then I can make a second version of this general concept that prioritizes RAM savings instead of CPU savings, and it will be easy to swap out the ones where it's a problem.

* The types of end pathfinders have been condensed down to three: PlanetPathfinderBasic, PlanetPathfinderConservative, and PlanetPathfinderWarden.
** There is nothing in there about any sort of long-term or short-term differences now.
** Additionally, when you find a path, it now requires you to pass in the faction and any extra debug info when you do so.

* Added a new DictionaryOfProtectedValDictionaries, which is presently unused. Thought I would need it on CacheForPathingMode, but those are being pooled by map-reload, so no.
** In general, a lot of the pathing code is now pooled way better between loads of the game. Previously... possibly it was lost and leaked? Maybe it was not leaking, but just kind of allocated in a useless place? Either way, fixed.

* Man, there's a whole bunch of other changes where things with pathfinding were really confusing to me. I didn't have time to document them all.
** However, the new approach is really clear and has comments or naming that explains what the rules are, and why. Also the code reads linearly from top to bottom, rather than jumping all over the place. So that also helps.
** For an end-faction-developer, very little is different. It does ask you for a "debug addendum" string, but that's just so that error messages will be more informatively precise if you should run into any.

* The sum total of these changes saves a LOT of memory, as well as making things load faster, as well as also eliminating the pathfinders-from-multiple-contexts bug. It also leads to some CPU speed improvements in several spots.
** It also solves what was definitively still a memory leak in terms of pathfinders.
*** After 10 loads of the game prior to these changes, there were 169,706 PathBetweenPlanetsForFaction-PathToReadOnly collections, with 25,661,700 capacity and 115,592 stored items. This is absolutely freaking huge!
*** Now, after 8 loads of the game, there are 79 collections, 420 total capacity, and 19 stored items. This is... uh... quite an improvement.

Issue History

Date Modified Username Field Change
Oct 29, 2021 8:28 pm BadgerBadger New Issue
Oct 29, 2021 8:28 pm BadgerBadger Status new => assigned
Oct 29, 2021 8:28 pm BadgerBadger Assigned To => Chris_McElligottPark
Nov 1, 2021 2:26 am BadgerBadger Relationship added related to 0025752
Nov 3, 2021 9:57 pm Chris_McElligottPark Status assigned => resolved
Nov 3, 2021 9:57 pm Chris_McElligottPark Resolution open => fixed
Nov 3, 2021 9:57 pm Chris_McElligottPark Fixed in Version => Beta 3.744 Pathfinding
Nov 3, 2021 9:57 pm Chris_McElligottPark Note Added: 0063176