junkdog / artemis-odb

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

[BUG] Null check needed in EntityProcessingSystem #655

Open bryanbrunt opened 2 years ago

bryanbrunt commented 2 years ago

I have found that a crash will sometimes occur without a null check in processSystem.

The code should be the following:

for (int i = 0, s = entities.size(); s > i; i++) { if (array[i] != null) process((Entity) array[i]); }

public abstract class EntityProcessingSystem extends EntitySystem {

/**
 * Creates a new EntityProcessingSystem.
 * @param aspect
 *         the aspect to match entities
 */
public EntityProcessingSystem(Aspect.Builder aspect) {
    super(aspect);
}

public EntityProcessingSystem() {
}

/**
 * Process a entity this system is interested in.
 * @param e
 *         the entity to process
 */
protected abstract void process(Entity e);

/** @inheritDoc */
@Override
protected final void processSystem() {
    Bag<Entity> entities = getEntities();
    Object[] array = entities.getData();
    for (int i = 0, s = entities.size(); s > i; i++) {
        process((Entity) array[i]);
    }
}

}