View Issue Details

IDProjectCategoryLast Update
0025689AI War 2Crash/ExceptionDec 20, 2021 6:36 pm
ReporterChris_McElligottPark Assigned ToChris_McElligottPark  
Status resolvedResolutionfixed 
Product VersionBeta 3.712 Loading Hotfix 
Summary0025689: Squads not in the central registry but still in the game.
DescriptionThis has been the root cause of the "ghosts" in multiplayer, but I've now seen it in single player also. I first saw this last week, when I made the change to LazyLoadSquadWrapper, because units would have a reference to a ship that they thought that they should be able to kill, but they were not able to find it.

These LazyLoadSquadWrappers for units in pursuit mode (or autotargeting in general) get filled via GameCommand periodically, and it's not worth it to actually find a reference to the unit itself at that time. Slow dictionary lookup on the main thread, no thanks. So the LazyLoadSquadWrapper gets created, with just the ID of the unit. When the unit decides to fire against the target, it will call GetSquad() on the wrapper, and the wrapper will do one of a few things:

1. If it finds the squad in the central registry, then hooray. It caches it and returns it, and we've successfully offloaded performance to a non-critical thread, and made it happen in a vaguely time-sliced way, also.

2. If the squad is missing from the central registry, it now checks the death registry. If the squad is in the death registry, then it knows that the target has died, and it returns null, and marks itself as perma-null. The targeting code likely then discards that whole wrapper and moves onto the next (usually they come in stacks of 5-10, depending on how many shots the gun can fire).

3. The last case is the problem case. If the squad is not in the central registry... but also not in the death registry... then where the heck did it go!? The answer is that it probably is still in existence and flying around shooting things. This is why we had ghosts in MP. In SP, it makes it so that ships can't shoot that target, instead. Much more subtle. Reloading the save fixes it.

So the question is: how is it being removed from the central registry, and why?

I'm not super certain how to handle this, other than to potentially add some auditing, maybe on a background thread, that just goes through the list of all ships (by iterating over each planetfaction, which is where ships are stored by root), and then finding any that don't exist in the main lookup, and fixing them.

It's possible that this is just a consequence of the concurrentdictionary, but I'm not entirely convinced. Now that the concurrentdictionary is part of the game code, another option would be to make an instrumented one that tracks keys in and out and see what happens. It's also possible that these are very temporary failures because of locks, and that if there were simply two tries rather than one, the second one would be successful.

This is going to be something I need to investigate soon, and getting it fixed for SP will fix the major remaining MP issue as well.
TagsNo tags attached.

Activities

Chris_McElligottPark

Dec 20, 2021 6:36 pm

administrator   ~0063536

Fixed recently.

Issue History

Date Modified Username Field Change
Oct 27, 2021 7:46 pm Chris_McElligottPark New Issue
Oct 27, 2021 7:46 pm Chris_McElligottPark Status new => assigned
Oct 27, 2021 7:46 pm Chris_McElligottPark Assigned To => Chris_McElligottPark
Dec 20, 2021 6:36 pm Chris_McElligottPark Status assigned => resolved
Dec 20, 2021 6:36 pm Chris_McElligottPark Resolution open => fixed
Dec 20, 2021 6:36 pm Chris_McElligottPark Note Added: 0063536