From c69dc8d7f78f765422f86cc97c6e4306d74b3263 Mon Sep 17 00:00:00 2001 From: Serovoy Date: Sun, 29 Apr 2018 17:23:48 +0300 Subject: [PATCH] fix native collection has not been disposed error --- Assets/GameCode/ZombieSimulatorBootstrap.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Assets/GameCode/ZombieSimulatorBootstrap.cs b/Assets/GameCode/ZombieSimulatorBootstrap.cs index ebec8bc..9d3f4a5 100644 --- a/Assets/GameCode/ZombieSimulatorBootstrap.cs +++ b/Assets/GameCode/ZombieSimulatorBootstrap.cs @@ -48,7 +48,7 @@ private static void NewGame() private static void CreateZombies(EntityManager entityManager) { - NativeArray zombies = new NativeArray(Settings.HumanCount, Allocator.Persistent); + NativeArray zombies = new NativeArray(Settings.HumanCount, Allocator.Temp); entityManager.CreateEntity(ZombieArchetype, zombies); for (int i = 0; i < Settings.HumanCount; i++) @@ -58,6 +58,8 @@ private static void CreateZombies(EntityManager entityManager) // We can tweak a few components to make more sense like this. InitializeZombie(entityManager, zombies[i], randomSpawnLocation); } + + zombies.Dispose(); } @@ -74,7 +76,7 @@ public static void InitializeZombie(EntityManager entityManager, Entity zombie, private static void CreateHumans(EntityManager entityManager) { int length = Settings.HumanCount;// + Settings.ZombieCount; - NativeArray humans = new NativeArray(length, Allocator.Persistent); + NativeArray humans = new NativeArray(length, Allocator.Temp); entityManager.CreateEntity(HumanArchetype, humans); for (int i = 0; i < length; i++) @@ -96,6 +98,7 @@ private static void CreateHumans(EntityManager entityManager) entityManager.AddSharedComponentData(human, HumanLook); } + humans.Dispose(); } private static float2 ComputeSpawnLocation()