junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
779 stars 112 forks source link

Unable to acces entities components from removed method inside EntityProcessingSystem #347

Closed MHOOO closed 9 years ago

MHOOO commented 9 years ago

Trying to migrate an existing codebase to artemis-odb, howeve, for some reason the method "removed" no longer gets an actual entity, but a bag of entity ids. Trying to get to the entity through world.getEntity(id) doesn't yield an actual entity. Whats going on here?

junkdog commented 9 years ago

Hmm, I'll see if I can reproduce it after work - is this when overriding EntitySystem's inserted/removed? What does your code look like?

You could try compiling against 0.11.4 and see if it solves the problem - 0.12.0 introduced some changes to how entity changes were propagated. It's possible a bug sneaked in too.

junkdog commented 9 years ago

Just to be sure, you're using 0.12.1 now?

MHOOO commented 9 years ago

Yes, should I use 0.10 instead? I noticed 0.10 still passes entities instead of IntBag instances.

Gesendet mit AquaMail für Android http://www.aqua-mail.com

Am 10. September 2015 20:41:25 schrieb Adrian Papari notifications@github.com:

Just to be sure, you're using 0.12.1 now?


Reply to this email directly or view it on GitHub: https://github.com/junkdog/artemis-odb/issues/347#issuecomment-139339179

junkdog commented 9 years ago

0.11.4 should be safe (same API as 0.12.1).

MHOOO commented 9 years ago

If it has the same API, won't I stumble across the same problem?

Gesendet mit AquaMail für Android http://www.aqua-mail.com

Am 10. September 2015 23:13:10 schrieb Adrian Papari notifications@github.com:

0.11.4 should be safe (same API as 0.12.1).


Reply to this email directly or view it on GitHub: https://github.com/junkdog/artemis-odb/issues/347#issuecomment-139380860

DaanVanYperen commented 9 years ago

@MHOOO As a workaround you could try flyweights, which can be used to iterate over IntBags.

@Override
public void removed(IntBag entities) {
    int[] ids = entities.getData();
    Entity flyweight = Entity.createFlyweight(world);
    for (int i = 0, s = entities.size(); s > i; i++) {
        flyweight.id = ids[i];
        removed(flyweight);
    }
}

Depending on your use case it might suffice.

kotcrab commented 9 years ago

I just stumbled on this issue, I'm using 0.12.1. SSCEE Output:

Added: ID: 0 Entity[0]
Removed: ID: 0 null

From what I checked when world.getEntity is called from removed, here entities.get(entityId) still returns proper entity but before that recyclingEntityFactory.has(entityId) is called and it returns true so null is returned.