From 0691b6d305eea94364dcbcd27c39f240ea2f1289 Mon Sep 17 00:00:00 2001 From: sjb933 Date: Thu, 3 Jan 2013 15:14:17 -0600 Subject: [PATCH] Modified RunnableHandler to process runnables FIFO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contrary to the expectations of every Handler, I found that the RunnableHandler processes runnables in a LIFO (stack-like fashion).   The correct approach is to process them in order and then clear the list, as I've done here.  This not only processes the items in FIFO order as expected, it also avoids any overhead of trying to remove the first element of the ArrayList. --- .../andengine/engine/handler/runnable/RunnableHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/org/andengine/engine/handler/runnable/RunnableHandler.java b/src/org/andengine/engine/handler/runnable/RunnableHandler.java index d0955ae3c..32937c283 100644 --- a/src/org/andengine/engine/handler/runnable/RunnableHandler.java +++ b/src/org/andengine/engine/handler/runnable/RunnableHandler.java @@ -38,9 +38,10 @@ public class RunnableHandler implements IUpdateHandler { public synchronized void onUpdate(final float pSecondsElapsed) { final ArrayList runnables = this.mRunnables; final int runnableCount = runnables.size(); - for(int i = runnableCount - 1; i >= 0; i--) { - runnables.remove(i).run(); + for(int i=0; i