Skip to content

Commit

Permalink
Ignore out of bounds exception in NearestSortingList, Closes #2742
Browse files Browse the repository at this point in the history
  • Loading branch information
oniatus committed May 2, 2017
1 parent 2e241e8 commit 9fbe788
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* 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.
*
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -239,9 +240,9 @@ public synchronized void initialise(Camera origin) {
public synchronized void initialiseAndPause(Camera origin) {
if (sortingTask != null || timer != null) {
logger.error("Mis-usages of initialise detected! Initialising again"
+ " before stopping the sorting process. Sorting is "
+ "stopped now, but it should be done by the user of "
+ "this class.");
+ " before stopping the sorting process. Sorting is "
+ "stopped now, but it should be done by the user of "
+ "this class.");
stop();
}
sortingTask = new SortTask(origin);
Expand All @@ -259,9 +260,9 @@ public synchronized void initialiseAndPause(Camera origin) {
public synchronized void initialise(Camera origin, long period, long initialDelay) {
if (sortingTask != null || timer != null) {
logger.error("Mis-usages of initialise detected! Initialising again"
+ " before stopping the sorting process. Sorting is "
+ "stopped now, but it should be done by the user of "
+ "this class.");
+ " before stopping the sorting process. Sorting is "
+ "stopped now, but it should be done by the user of "
+ "this class.");
stop();
}
sortPeriod = period;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9fbe788

Please sign in to comment.