Skwizzy / SPT-LootingBots

AI Looting mod for Singleplayer Tarkov
https://hub.sp-tarkov.com/files/file/1096-looting-bots/#overview
29 stars 11 forks source link

Exception in ActiveLootCache #109

Closed Skwizzy closed 3 months ago

Skwizzy commented 4 months ago

Reported by MusicManiac and RPRaptor

Logs are filled with the following exception:

[Error :LootingBots] System.NullReferenceException
at (wrapper managed-to-native) UnityEngine.Object.GetName(UnityEngine.Object)
at UnityEngine.Object.get_name () [0x00001] in <ca21460feb9c47d0ac337b9893474cc6>:0
at LootingBots.Patch.Util.ActiveLootCache+<>c__DisplayClass7_0.<Cleanup>b__0 (System.Collections.Generic.KeyValuePair`2[TKey,TValue] keyValue) [0x00007] in <af0e2afa5f0c4e8e9600d84bb1fc65b2>:0
at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].ToList () [0x0001b] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
at LootingBots.Patch.Util.ActiveLootCache.Cleanup (EFT.BotOwner botOwner) [0x00039] in <af0e2afa5f0c4e8e9600d84bb1fc65b2>:0

Not exactly sure how this can happen. When a bot detects loot to find, it is added to the active loot map with the item id as the key and the value is the BotOwner that detected the item. In this instance, one of the BotOwners in this map does not have its name property which usually means the bot has despawned. Adding some extra protection during loot finding to make sure the BotOwner is defined before adding something to the cache

Skwizzy commented 4 months ago

I delivered a change adding some extra protection to prevent this exception 7121065

Skwizzy commented 3 months ago

Reopening as Solarint mentioned this exception was seen again in 1.3.0

Skwizzy commented 3 months ago

Was able to recreate finally. During the second raid, after bot 90-92 spawns this exception is seen for me. I think this has to do with the fact that when a bot dies while looting, its BotOwner ref is not being removed from the loot cache.

Adding a patch for the BotOwner.dispose method to cleanup the cache when a bot dies