artemis-odb icon indicating copy to clipboard operation
artemis-odb copied to clipboard

[BUG] Null check needed in EntityProcessingSystem

Open bryanbrunt opened this issue 2 years ago • 0 comments

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]);
    }
}

}

bryanbrunt avatar May 20 '22 20:05 bryanbrunt