{"action":"created","issue":{"url":"https://api.github.com/repos/libgdx/ashley/issues/173","labels_url":"https://api.github.com/repos/libgdx/ashley/issues/173/labels{/name}","comments_url":"https://api.github.com/repos/libgdx/ashley/issues/173/comments","events_url":"https://api.github.com/repos/libgdx/ashley/issues/173/events","html_url":"https://github.com/libgdx/ashley/issues/173","id":86200616,"number":173,"title":"Define behavior when redundantly adding/removing entities","user":{"login":"Antag99","id":7714919,"avatar_url":"https://avatars.githubusercontent.com/u/7714919?v=3","gravatar_id":"","url":"https://api.github.com/users/Antag99","html_url":"https://github.com/Antag99","followers_url":"https://api.github.com/users/Antag99/followers","following_url":"https://api.github.com/users/Antag99/following{/other_user}","gists_url":"https://api.github.com/users/Antag99/gists{/gist_id}","starred_url":"https://api.github.com/users/Antag99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Antag99/subscriptions","organizations_url":"https://api.github.com/users/Antag99/orgs","repos_url":"https://api.github.com/users/Antag99/repos","events_url":"https://api.github.com/users/Antag99/events{/privacy}","received_events_url":"https://api.github.com/users/Antag99/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-08T14:35:26Z","updated_at":"2015-06-08T16:19:41Z","closed_at":null,"body":"What should happen when an entity is added twice? The current behaviour isn't too pretty: the entity is added to two slots in the array. In addition to this, the current operation delay mechanism leads to bad behavior when adding/removing entities inside of listeners or when an `EntitySystem` is executing. (See #161 for details.) I created two test cases for the behaviour when adding an entity twice:\r\n```java\r\n@Test\r\npublic void addEntityTwice () {\r\n\tEngine engine = new Engine();\r\n\tEntity entity = new Entity();\r\n\tengine.addEntity(entity);\r\n\tengine.addEntity(entity);\r\n\tassertEquals(1, engine.getEntities().size());\r\n}\r\n\r\n@Test\r\npublic void addEntityTwiceInListener () {\r\n\tfinal Entity entityA = new Entity();\r\n\tfinal Entity entityB = new Entity();\r\n\tfinal Engine engine = new Engine();\r\n\r\n\tengine.addEntityListener(new EntityListener() {\r\n\t\t@Override\r\n\t\tpublic void entityAdded (Entity entity) {\r\n\t\t\tengine.addEntity(entityB);\r\n\t\t\tengine.addEntity(entityB);\r\n\t\t}\r\n\r\n\t\t@Override\r\n\t\tpublic void entityRemoved (Entity entity) {\r\n\t\t}\r\n\t});\r\n\r\n\tengine.addEntity(entityA);\r\n\r\n\tassertEquals(2, engine.getEntities().size());\r\n}\r\n```\r\nAlso worth noting is that it is perfectly allowed to do something evil such as nesting `Engine` updates; this should throw an exception rather than silently allowing it."},"comment":{"url":"https://api.github.com/repos/libgdx/ashley/issues/comments/110061393","html_url":"https://github.com/libgdx/ashley/issues/173#issuecomment-110061393","issue_url":"https://api.github.com/repos/libgdx/ashley/issues/173","id":110061393,"user":{"login":"saltares","id":570314,"avatar_url":"https://avatars.githubusercontent.com/u/570314?v=3","gravatar_id":"","url":"https://api.github.com/users/saltares","html_url":"https://github.com/saltares","followers_url":"https://api.github.com/users/saltares/followers","following_url":"https://api.github.com/users/saltares/following{/other_user}","gists_url":"https://api.github.com/users/saltares/gists{/gist_id}","starred_url":"https://api.github.com/users/saltares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saltares/subscriptions","organizations_url":"https://api.github.com/users/saltares/orgs","repos_url":"https://api.github.com/users/saltares/repos","events_url":"https://api.github.com/users/saltares/events{/privacy}","received_events_url":"https://api.github.com/users/saltares/received_events","type":"User","site_admin":false},"created_at":"2015-06-08T16:19:41Z","updated_at":"2015-06-08T16:19:41Z","body":"Checking whether the entity is registered with an engine should be easy enough because the entityId is only set when that's the case.\r\n\r\n* Do we wanna throw when we try to add an entity that's registered with an engine already?\r\n* We can also throw when trying to do nesting engine updates.\r\n\r\nWe could very well say that adding an entity twice is undefined behavior and be done with it. However, I like trying to make Ashley hard to break, so we should probably cater for this problem."}}