add lock around adding to cached handled paths
This commit is contained in:
@@ -17,6 +17,7 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase
|
|||||||
private readonly string[] _fileTypesToHandle = ["tmb", "pap", "avfx", "atex", "sklb", "eid", "phyb", "scd", "skp", "shpk"];
|
private readonly string[] _fileTypesToHandle = ["tmb", "pap", "avfx", "atex", "sklb", "eid", "phyb", "scd", "skp", "shpk"];
|
||||||
private readonly HashSet<GameObjectHandler> _playerRelatedPointers = [];
|
private readonly HashSet<GameObjectHandler> _playerRelatedPointers = [];
|
||||||
private HashSet<IntPtr> _cachedFrameAddresses = [];
|
private HashSet<IntPtr> _cachedFrameAddresses = [];
|
||||||
|
private readonly object _cacheAdditionLock = new();
|
||||||
|
|
||||||
public TransientResourceManager(ILogger<TransientResourceManager> logger, TransientConfigService configurationService,
|
public TransientResourceManager(ILogger<TransientResourceManager> logger, TransientConfigService configurationService,
|
||||||
DalamudUtilService dalamudUtil, MareMediator mediator) : base(logger, mediator)
|
DalamudUtilService dalamudUtil, MareMediator mediator) : base(logger, mediator)
|
||||||
@@ -189,7 +190,10 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase
|
|||||||
private void DalamudUtil_FrameworkUpdate()
|
private void DalamudUtil_FrameworkUpdate()
|
||||||
{
|
{
|
||||||
_cachedFrameAddresses = _playerRelatedPointers.Select(c => c.CurrentAddress()).ToHashSet();
|
_cachedFrameAddresses = _playerRelatedPointers.Select(c => c.CurrentAddress()).ToHashSet();
|
||||||
|
lock (_cacheAdditionLock)
|
||||||
|
{
|
||||||
_cachedHandledPaths.Clear();
|
_cachedHandledPaths.Clear();
|
||||||
|
}
|
||||||
foreach (var item in TransientResources.Where(item => !_dalamudUtil.IsGameObjectPresent(item.Key)).Select(i => i.Key).ToList())
|
foreach (var item in TransientResources.Where(item => !_dalamudUtil.IsGameObjectPresent(item.Key)).Select(i => i.Key).ToList())
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Object not present anymore: {addr}", item.ToString("X"));
|
Logger.LogDebug("Object not present anymore: {addr}", item.ToString("X"));
|
||||||
@@ -218,7 +222,10 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase
|
|||||||
// ignore files already processed this frame
|
// ignore files already processed this frame
|
||||||
if (_cachedHandledPaths.Contains(gamePath)) return;
|
if (_cachedHandledPaths.Contains(gamePath)) return;
|
||||||
|
|
||||||
|
lock (_cacheAdditionLock)
|
||||||
|
{
|
||||||
_cachedHandledPaths.Add(gamePath);
|
_cachedHandledPaths.Add(gamePath);
|
||||||
|
}
|
||||||
|
|
||||||
// replace individual mtrl stuff
|
// replace individual mtrl stuff
|
||||||
if (filePath.StartsWith("|", StringComparison.OrdinalIgnoreCase))
|
if (filePath.StartsWith("|", StringComparison.OrdinalIgnoreCase))
|
||||||
@@ -234,15 +241,21 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase
|
|||||||
|
|
||||||
// ignore files to not handle
|
// ignore files to not handle
|
||||||
if (!_fileTypesToHandle.Any(type => gamePath.EndsWith(type, StringComparison.OrdinalIgnoreCase)))
|
if (!_fileTypesToHandle.Any(type => gamePath.EndsWith(type, StringComparison.OrdinalIgnoreCase)))
|
||||||
|
{
|
||||||
|
lock (_cacheAdditionLock)
|
||||||
{
|
{
|
||||||
_cachedHandledPaths.Add(gamePath);
|
_cachedHandledPaths.Add(gamePath);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore files not belonging to anything player related
|
// ignore files not belonging to anything player related
|
||||||
if (!_cachedFrameAddresses.Contains(gameObject))
|
if (!_cachedFrameAddresses.Contains(gameObject))
|
||||||
|
{
|
||||||
|
lock (_cacheAdditionLock)
|
||||||
{
|
{
|
||||||
_cachedHandledPaths.Add(gamePath);
|
_cachedHandledPaths.Add(gamePath);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user