Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix native collection has not been disposed error #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Assets/GameCode/ZombieSimulatorBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void NewGame()

private static void CreateZombies(EntityManager entityManager)
{
NativeArray<Entity> zombies = new NativeArray<Entity>(Settings.HumanCount, Allocator.Persistent);
NativeArray<Entity> zombies = new NativeArray<Entity>(Settings.HumanCount, Allocator.Temp);
entityManager.CreateEntity(ZombieArchetype, zombies);

for (int i = 0; i < Settings.HumanCount; i++)
Expand All @@ -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();
}


Expand All @@ -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<Entity> humans = new NativeArray<Entity>(length, Allocator.Persistent);
NativeArray<Entity> humans = new NativeArray<Entity>(length, Allocator.Temp);
entityManager.CreateEntity(HumanArchetype, humans);

for (int i = 0; i < length; i++)
Expand All @@ -96,6 +98,7 @@ private static void CreateHumans(EntityManager entityManager)
entityManager.AddSharedComponentData(human, HumanLook);
}

humans.Dispose();
}

private static float2 ComputeSpawnLocation()
Expand Down