Ash icon indicating copy to clipboard operation
Ash copied to clipboard

Removing entity that was removed before causes entity list change.

Open SergeyRomanko opened this issue 8 years ago • 2 comments

Hi! Here is code that illustrates issue.

`package { import flash.display.Sprite;

import ash.core.Engine;
import ash.core.Entity;

public class AshTest extends Sprite {

    public var engine:Engine = new Engine();

    public function AshTest() {

        var a:Entity = new Entity("a");
        var b:Entity = new Entity("b");
        var c:Entity = new Entity("c");
        var d:Entity = new Entity("d");

        engine.addEntity(a);
        engine.addEntity(b);
        engine.addEntity(c);
        engine.addEntity(d);

        print();    //a, b, c, d

        engine.removeEntity(b);
        engine.removeEntity(c);

        print();    //a, d  <-- ok

        engine.removeEntity(b);     //<- delete b again. problem here

        print();    //a, c, d <-- error

    }

    private function print():void {
        var result:Array = [];
        var entites:Vector.<Entity> = engine.entities;
        for (var i:int = 0; i < entites.length; i++) {
            result[result.length] = entites[i].name;
        }
        trace(result.join(", "));
    }

}

}`

It's self-evident that programmer should not remove entities that are already removed. But it would be better if engine will work correctly in this situation.

SergeyRomanko avatar Apr 22 '16 11:04 SergeyRomanko

This is due to

https://github.com/richardlord/Ash/blob/master/src/ash/core/EntityList.as#L48

dyarosla avatar May 26 '17 18:05 dyarosla

Yep, I know why this happen. This is still issue to solve.

SergeyRomanko avatar May 26 '17 18:05 SergeyRomanko