From 6df10dfe0162152857377420e1811b17437c794b Mon Sep 17 00:00:00 2001 From: Barry Rowe Date: Sun, 10 Apr 2016 20:59:07 -0400 Subject: [PATCH] Recreating issue #214 Issue number #214 is recreated in this new unit test if the commented line is uncommented. Line 518 in PooledEngineTests.java --- .../ashley/core/PooledEngineTests.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/ashley/tests/com/badlogic/ashley/core/PooledEngineTests.java b/ashley/tests/com/badlogic/ashley/core/PooledEngineTests.java index e529c03a..da73f255 100644 --- a/ashley/tests/com/badlogic/ashley/core/PooledEngineTests.java +++ b/ashley/tests/com/badlogic/ashley/core/PooledEngineTests.java @@ -455,4 +455,81 @@ public void assertAgainst(Entity entity) { assertEquals("After Update Total Should be right on iteration " + i, expectedTotal - changePerIteration, engine.getEntitiesFor(Family.all(UniquePooledCompnentA.class).get()).size()); } } + + + private static class FollowerComponent implements Component, Poolable{ + + @Override + public void reset() { + + } + } + + private static class EnemyComponent implements Component, Poolable{ + @Override + public void reset() { + + } + } + + private static class OtherComponent implements Component, Poolable{ + + @Override + public void reset() { + + } + } + + @Test + public void removeDuringEntityRemovedHandledOk(){ + final PooledEngine engine = new PooledEngine(); + + final Entity enemy = engine.createEntity(); + enemy.add(engine.createComponent(EnemyComponent.class)); + engine.addEntity(enemy); + + final Entity otherFollower = engine.createEntity(); + otherFollower.add(engine.createComponent(FollowerComponent.class)); + otherFollower.add(engine.createComponent(OtherComponent.class)); + engine.addEntity(otherFollower); + + final Entity enemyWithFollower = engine.createEntity(); + enemyWithFollower.add(engine.createComponent(EnemyComponent.class)); + enemyWithFollower.add(engine.createComponent(FollowerComponent.class)); + engine.addEntity(enemyWithFollower); + + + engine.addEntityListener(Family.all(EnemyComponent.class).get(), new EntityListener() { + private boolean isMidRemoval = false; + private ComponentMapper fm = ComponentMapper.getFor(FollowerComponent.class); + @Override + public void entityAdded(Entity entity) { + + } + + @Override + public void entityRemoved(Entity entity) { + ImmutableArray followers = engine.getEntitiesFor(Family.all(FollowerComponent.class).get()); + + for(Entity follower: followers){ + FollowerComponent fc = fm.get(follower); + assertTrue("Follower Component is not defined for entity matching Family.all(FollowerComponent.class)", fc != null); + //UNCOMMENT THIS TO REPRODUCE ISSUE #214 + //follower.removeAll(); + engine.removeEntity(follower); + } + } + }); + + engine.addSystem(new EntitySystem() { + @Override + public void update(float deltaTime) { + super.update(deltaTime); + getEngine().removeEntity(enemy); + } + }); + + engine.update(0.16f); + engine.update(0.16f); + } }