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

pool.onEntityReleased checks if the entity is destroyed #32

Merged
merged 2 commits into from
Aug 29, 2015
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions Entitas/Entitas/Pool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ protected void updateGroupsComponentReplaced(Entity entity, int index, IComponen
}

protected void onEntityReleased(Entity entity) {
if(entity._isEnabled){
throw new EntityIsNotDestroyedException();
}
entity.OnEntityReleased -= _cachedOnEntityReleased;
_retainedEntities.Remove(entity);
_reusableEntities.Push(entity);
Expand All @@ -167,5 +170,11 @@ public PoolDoesNotContainEntityException(Entity entity, string message) :
base(message + "\nPool does not contain entity " + entity) {
}
}

public class EntityIsNotDestroyedException : Exception {
public EntityIsNotDestroyedException() :
base("Entity is not destroyed yet!") {
}
}
}

5 changes: 5 additions & 0 deletions Tests/Tests/Entitas/describe_Pool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ void when_created() {
reusedEntity.should_be_same(e);
didDispatch.should_be(1);
};

it["throws if Entity is released before it is destroyed"] = expect<EntityIsNotDestroyedException>(() => {
var e = pool.CreateEntity();
e.Release();
});

it["dispatches OnGroupCreated when creating a new group"] = () => {
Group eventGroup = null;
Expand Down