Android: Fixed race-condition on GLSurfaceView destroy, fixed MouseEvents for flyCam rotation bug

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7536 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
kim..ng 14 years ago
parent e5478faae0
commit 8cefea550e
  1. 5
      engine/src/android/com/jme3/app/android/AndroidApplication.java
  2. 36
      engine/src/android/com/jme3/input/android/AndroidInput.java
  3. 8
      engine/src/android/com/jme3/system/android/OGLESContext.java

@ -33,6 +33,7 @@ package com.jme3.app.android;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -62,6 +63,7 @@ import com.jme3.app.AndroidHarness;
@Deprecated @Deprecated
public abstract class AndroidApplication extends Application implements DialogInterface.OnClickListener public abstract class AndroidApplication extends Application implements DialogInterface.OnClickListener
{ {
protected final static Logger logger = Logger.getLogger(AndroidApplication.class.getName());
protected Node rootNode = new Node("Root Node"); protected Node rootNode = new Node("Root Node");
protected Node guiNode = new Node("Gui Node"); protected Node guiNode = new Node("Gui Node");
@ -258,6 +260,9 @@ public abstract class AndroidApplication extends Application implements DialogIn
} }
} }
final String sTrace = s; final String sTrace = s;
logger.severe(t != null ? t.toString() : "Failed");
logger.severe((errorMsg != null ? errorMsg + ": " : "") + sTrace);
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() public void run()

@ -30,7 +30,8 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
private AndroidTouchInputListener listenerTouch = null; private AndroidTouchInputListener listenerTouch = null;
private ScaleGestureDetector scaledetector; private ScaleGestureDetector scaledetector;
private GestureDetector detector; private GestureDetector detector;
private Vector2f lastPos = new Vector2f(); private int lastX;
private int lastY;
private boolean dragging = false; private boolean dragging = false;
private List<Object> currentEvents = new ArrayList<Object>(); private List<Object> currentEvents = new ArrayList<Object>();
@ -175,21 +176,23 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
this.detector.onTouchEvent(event); this.detector.onTouchEvent(event);
this.scaledetector.onTouchEvent(event); this.scaledetector.onTouchEvent(event);
int newX = getWidth() - (int) event.getX();
int newY = (int) event.getY();
switch (event.getAction()) switch (event.getAction())
{ {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
// Store current pos
lastPos.set(event.getX(),event.getY());
if (FIRE_MOUSE_EVENTS) if (FIRE_MOUSE_EVENTS)
{ {
// Handle mouse events // Handle mouse events
btn = new MouseButtonEvent(0, true, (int)lastPos.getX(), (int)lastPos.getY()); btn = new MouseButtonEvent(0, true, newX, newY);
btn.setTime(event.getEventTime()); btn.setTime(event.getEventTime());
processEvent(btn); processEvent(btn);
} }
// Store current pos
lastX = -1;
lastY = -1;
// Handle gesture events // Handle gesture events
touch = new TouchEvent(TouchEvent.Type.GRABBED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null); touch = new TouchEvent(TouchEvent.Type.GRABBED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null);
@ -203,14 +206,18 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
if (FIRE_MOUSE_EVENTS) if (FIRE_MOUSE_EVENTS)
{ {
// Handle mouse events // Handle mouse events
btn = new MouseButtonEvent(0, false, (int)event.getX(), (int)event.getY()); btn = new MouseButtonEvent(0, false, newX, newY);
btn.setTime(event.getEventTime()); btn.setTime(event.getEventTime());
processEvent(btn); processEvent(btn);
} }
// Store current pos
lastX = -1;
lastY = -1;
// Handle gesture events // Handle gesture events
if(dragging) if(dragging)
{ {
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STOPPED,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null); touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STOPPED,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null);
processEvent(touch); processEvent(touch);
} }
touch = new TouchEvent(TouchEvent.Type.RELEASED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null); touch = new TouchEvent(TouchEvent.Type.RELEASED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null);
@ -222,22 +229,21 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
if(!scaledetector.isInProgress()) if(!scaledetector.isInProgress())
{ {
if(!dragging) if(!dragging)
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STARTED,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null); touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STARTED,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null);
else else
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.RUNNING,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null); touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.RUNNING,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null);
processEvent(touch); processEvent(touch);
dragging=true; dragging=true;
} }
if (FIRE_MOUSE_EVENTS) if (FIRE_MOUSE_EVENTS)
{ {
int newX = getWidth() - (int) event.getX();
int newY = (int) event.getY();
int dx; int dx;
int dy; int dy;
if (lastPos.getX() != -1){ if (lastX != -1){
dx = newX - (int)lastPos.getX(); dx = newX - lastX;
dy = newY - (int)lastPos.getY(); dy = newY - lastY;
}else{ }else{
dx = 0; dx = 0;
dy = 0; dy = 0;
@ -246,6 +252,8 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput,
mot.setTime(event.getEventTime()); mot.setTime(event.getEventTime());
processEvent(mot); processEvent(mot);
} }
lastX = newX;
lastY = newY;
bWasHandled = true; bWasHandled = true;
break; break;

@ -295,8 +295,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
public void onDrawFrame(GL10 gl) public void onDrawFrame(GL10 gl)
{ {
if (!created.get())
throw new IllegalStateException("onDrawFrame without create");
if (needClose.get()) if (needClose.get())
{ {
@ -306,6 +304,10 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
if (renderable.get()) if (renderable.get())
{ {
if (!created.get())
throw new IllegalStateException("onDrawFrame without create");
milliStart = System.currentTimeMillis(); milliStart = System.currentTimeMillis();
@ -369,7 +371,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
public void destroy() public void destroy()
{ {
destroy(false); destroy(true);
} }
protected void waitFor(boolean createdVal) protected void waitFor(boolean createdVal)

Loading…
Cancel
Save