haxenme/nme

[android] Rare crash with TimerTask

Closed this issue · 5 comments

Fatal Exception: java.lang.IllegalStateException
TimerTask is canceled
java.util.Timer.scheduleImpl (Timer.java:576)
java.util.Timer.schedule (Timer.java:459)
org.haxe.nme.MainView.HandleResult (MainView.java:285)
org.haxe.nme.MainView.onPollHX (MainView.java:296)
org.haxe.nme.MainView$1.run (MainView.java:83)
android.opengl.GLSurfaceView$GLThread.guardedRun (GLSurfaceView.java:1472)
android.opengl.GLSurfaceView$GLThread.run (GLSurfaceView.java:1249)

https://docs.oracle.com/javase/7/docs/api/java/util/Timer.html#schedule(java.util.TimerTask,%20java.util.Date)
IllegalStateException - if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.

            pendingTimer = new TimerTask() {
                @Override public void run() {
                   me.queuePoll();
                }
            };

            mTimer.schedule(pendingTimer,delayMs);

pendingTimer is brand new, and this is protected by a sempahore, so it cannot have been scheduled or canceled.

From https://developer.android.com/reference/java/util/Timer Implementation note: All constructors start a timer thread.

       if (pendingTimer != null) { //Pause the Haxe Thread
         pendingTimer.cancel();
       }

This is the non thread safe part.

git revert 5f208aa898a35f1af03c537e8872cf422723b8d6