fix: Prevent cascading deletes during world deserialization (#2298)

### Summary

Fixes an issue where deleting entities during world load can cause cascading delete failures when the world is not fully loaded.
This commit is contained in:
Kamron Batman 2025-12-28 17:54:53 -08:00 committed by GitHub
parent cc4a679fb0
commit 9887818e7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -345,8 +345,21 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
_entities.Clear();
_entities.TrimExcess();
_entities = null;
if (_toDelete != null)
{
foreach (var t in _toDelete)
{
t.Delete();
}
_toDelete.Clear();
_toDelete = null;
}
}
private static List<T> _toDelete;
private unsafe void InternalDeserialize(string filePath, int index, Dictionary<ulong, string> typesDb)
{
using var mmf = MemoryMappedFile.CreateFromFile(filePath, FileMode.Open);
@ -415,7 +428,8 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
}
}
t.Delete();
_toDelete ??= [];
_toDelete.Add(t);
}
}