Skip to content

Commit f4221e4

Browse files
committed
Use UWE batch cache instead of our own. This guards against holding on to stale batch references.
1 parent 3456686 commit f4221e4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

NitroxClient/GameLogic/Entities.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ public class Entities
2323
private readonly DefaultEntitySpawner defaultEntitySpawner = new DefaultEntitySpawner();
2424
private readonly SerializedEntitySpawner serializedEntitySpawner = new SerializedEntitySpawner();
2525
private readonly Dictionary<TechType, IEntitySpawner> customSpawnersByTechType = new Dictionary<TechType, IEntitySpawner>();
26-
private readonly Dictionary<Int3, BatchCells> batchCellsById = new Dictionary<Int3, BatchCells>();
26+
private readonly Dictionary<Int3, BatchCells> batchCellsById;
2727
private readonly CellRootSpawner cellRootSpawner = new CellRootSpawner();
2828

2929
public Entities(IPacketSender packetSender)
3030
{
3131
this.packetSender = packetSender;
32+
batchCellsById = (Dictionary<Int3, BatchCells>)LargeWorldStreamer.main.cellManager.ReflectionGet("batch2cells");
3233

3334
customSpawnersByTechType[TechType.Crash] = new CrashEntitySpawner();
3435
customSpawnersByTechType[TechType.Reefback] = new ReefbackEntitySpawner(defaultEntitySpawner);
@@ -84,9 +85,7 @@ private EntityCell EnsureCell(Entity entity)
8485

8586
if (!batchCellsById.TryGetValue(batchId, out batchCells))
8687
{
87-
LargeWorldStreamer.main.cellManager.UnloadBatchCells(batchId); // Just in case
8888
batchCells = LargeWorldStreamer.main.cellManager.InitializeBatchCells(batchId);
89-
batchCellsById.Add(batchId, batchCells);
9089
}
9190

9291
entityCell = batchCells.Get(cellId, entity.AbsoluteEntityCell.Level);

0 commit comments

Comments
 (0)