Ignore out of bounds exception in NearestSortingList, Closes
* sorting of the entities. This class only tries to keep the elements sorted,
* but does not guarantee it.
* <br><br>
- * It it therefor use full for graphics purposes, to keep track of the nearest
+ * It it therefore use full for graphics purposes, to keep track of the nearest
* entities to draw.
*
*/
@@ -99,11 +99,12 @@ public boolean contains(EntityRef e) {
* from this container.
*
* @param e The entity to add. Must have a LocationComponent or an
- * IlligalArgumentException is thrown.
+ * IllegalArgumentException is thrown.
*/
public synchronized void add(EntityRef e) {
if (e.getComponent(LocationComponent.class) == null) {
logger.warn("Adding entity without LocationComponent to container that sorts on location. Entity: {}", e);
+ throw new IllegalArgumentException("Entity has no LocationComponent");
}
//new entities are inserted to make sure that new entities are drawn first.
//Since it is likely the players wants to see new entities over existing ones
@@ -452,6 +453,14 @@ private void sort() {
logger.warn("Entities destroyed during sorting process. Sorting is skipped this round.");
clearQueue();
return;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // see https://github.com/MovingBlocks/Terasology/issues/2742
+ // This happens when the component lookup used for sorting is async with the game thread,
+ // e.g. when a large amount of entities is destroyed or created in a short timespan.
+ // as long as this occurs rarely, it can be ignored.
+ logger.warn("Something went wrong during sorting process. Sorting is skipped this round.");
+ clearQueue();
+ return;
}
processQueueAndSetEntities(newEnts);
}
