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: [#2726] Entity manager memory leak #2727

Merged
merged 2 commits into from
Aug 2, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ are returned

### Fixed

- Fixed memory leak in the internal `ex.EntityManager`, it did not properly clear internal state when removing entities
- Fixed issue where scaling a `ex.TileMap` didn't properly offscreen cull due to the bounds not scaling properly.
- Fixed issue where `ex.Text.flipHorizontal` or `ex.Text.flipVertical` would not work
- Fixed issue where overriding existing components did not work properly because of deferred component removal
Expand Down
1 change: 1 addition & 0 deletions src/engine/EntityComponentSystem/EntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class EntityManager<ContextType = any> implements Observer<RemovedCompone
}
this.removeEntity(entity, false);
}
this._entitiesToRemove.length = 0;
}

public processComponentRemovals(): void {
Expand Down
3 changes: 3 additions & 0 deletions src/spec/EntityManagerSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ describe('An EntityManager', () => {

expect(entityManager.entities.length).toBe(2);
entityManager.clear();
expect((entityManager as any)._entitiesToRemove.length).toBe(2);
expect(entityManager.entities.length).toBe(2);
entityManager.processEntityRemovals();
expect(entityManager.entities.length).toBe(0);
expect((entityManager as any)._entitiesToRemove.length).toBe(0);
});
});