[android] Fix for race condition with timer.
@@ -36,6 +36,7 @@ import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;
import java.util.TimerTask;
+import java.util.concurrent.Semaphore;
/**
* A simple GLSurfaceView sub-class that demonstrate how to perform
@@ -66,6 +67,7 @@ class MainView extends GLSurfaceView {
boolean onPaused;
Runnable pollMe;
TimerTask pendingTimer;
+ Semaphore handleResultSemaphore;
boolean renderPending = false;
@@ -80,6 +82,7 @@ class MainView extends GLSurfaceView {
pollMe = new Runnable() {
@Override public void run() { me.onPollHX(); }
};
+ handleResultSemaphore = new Semaphore(1);
translucent = inTranslucent;
getHolder().setFormat(
@@ -251,14 +254,14 @@ class MainView extends GLSurfaceView {
// Haxe thread
public void HandleResult(int inCode)
{
+ if(handleResultSemaphore.tryAcquire()) {
if (inCode==resTerminate)
{
- //Log.v("VIEW","Terminate Request.");
+ Log.v("VIEW","Terminate Request.");
mActivity.onNMEFinish();
return;
}
-
double wake = NME.getNextWake();
int delayMs = (int)(wake * 1000);
@@ -281,6 +284,8 @@ class MainView extends GLSurfaceView {
mTimer.schedule(pendingTimer,delayMs);
}
+ handleResultSemaphore.release();
+ }
}
