diff --git a/src/AcDream.App/Rendering/Wb/DatCollectionAdapter.cs b/src/AcDream.App/Rendering/Wb/DatCollectionAdapter.cs index 874fd33..3b661e2 100644 --- a/src/AcDream.App/Rendering/Wb/DatCollectionAdapter.cs +++ b/src/AcDream.App/Rendering/Wb/DatCollectionAdapter.cs @@ -118,6 +118,7 @@ internal sealed class DatDatabaseWrapper : IDatDatabase { private readonly DatDatabase _db; private readonly ConcurrentDictionary<(Type, uint), IDBObj> _cache = new(); + private readonly object _lock = new(); public DatDatabaseWrapper(DatDatabase db) { @@ -142,20 +143,33 @@ internal sealed class DatDatabaseWrapper : IDatDatabase return true; } - if (_db.TryGet(fileId, out value)) + lock (_lock) { - _cache.TryAdd((typeof(T), fileId), value); - return true; + if (_db.TryGet(fileId, out value)) + { + _cache.TryAdd((typeof(T), fileId), value); + return true; + } } return false; } - public bool TryGetFileBytes(uint fileId, [MaybeNullWhen(false)] out byte[] value) => - _db.TryGetFileBytes(fileId, out value); + public bool TryGetFileBytes(uint fileId, [MaybeNullWhen(false)] out byte[] value) + { + lock (_lock) + { + return _db.TryGetFileBytes(fileId, out value); + } + } - public bool TryGetFileBytes(uint fileId, ref byte[] bytes, out int bytesRead) => - _db.TryGetFileBytes(fileId, ref bytes, out bytesRead); + public bool TryGetFileBytes(uint fileId, ref byte[] bytes, out int bytesRead) + { + lock (_lock) + { + return _db.TryGetFileBytes(fileId, ref bytes, out bytesRead); + } + } public bool TrySave(T obj, int iteration = 0) where T : IDBObj => throw new NotSupportedException("DatDatabaseWrapper is read-only."); diff --git a/src/AcDream.App/Rendering/Wb/WbMeshAdapter.cs b/src/AcDream.App/Rendering/Wb/WbMeshAdapter.cs index b5c6a80..ed8b8ef 100644 --- a/src/AcDream.App/Rendering/Wb/WbMeshAdapter.cs +++ b/src/AcDream.App/Rendering/Wb/WbMeshAdapter.cs @@ -10,7 +10,6 @@ using DatReaderWriter.DBObjs; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Silk.NET.OpenGL; -using WorldBuilder.Shared.Models; using WorldBuilder.Shared.Services; namespace AcDream.App.Rendering.Wb;