Android: fixed crash in harness if inputManager is not initialized yet

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7647 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
kim..ng 14 years ago
parent c9993d87b8
commit f02c21a51f
  1. 20
      engine/src/android/com/jme3/app/AndroidHarness.java
  2. 21
      engine/src/android/com/jme3/system/android/OGLESContext.java

@ -11,7 +11,6 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import com.jme3.app.Application; import com.jme3.app.Application;
import com.jme3.app.android.AndroidApplication;
import com.jme3.input.TouchInput; import com.jme3.input.TouchInput;
import com.jme3.input.android.AndroidInput; import com.jme3.input.android.AndroidInput;
import com.jme3.input.controls.TouchListener; import com.jme3.input.controls.TouchListener;
@ -37,8 +36,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
protected String appClass = "jme3test.android.Test"; protected String appClass = "jme3test.android.Test";
protected Application app = null; protected Application app = null;
protected boolean debug = false; protected boolean debug = false;
final private String ESCAPE_EVENT = "TouchEscape"; final private String ESCAPE_EVENT = "TouchEscape";
@Override @Override
@ -54,16 +52,14 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
AppSettings settings = new AppSettings(true); AppSettings settings = new AppSettings(true);
AndroidInput input = new AndroidInput(this); AndroidInput input = new AndroidInput(this);
// Create application instance // Create application instance
try{ try{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass); Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass);
app = clazz.newInstance(); app = clazz.newInstance();
}catch (Exception ex){ }catch (Exception ex){
ex.printStackTrace(); handleError("Class " + appClass + " init failed", ex);
} }
app.setSettings(settings); app.setSettings(settings);
@ -77,10 +73,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
{ {
view = ctx.createView(input); view = ctx.createView(input);
} }
setContentView(view); setContentView(view);
app.inputManager.addMapping(ESCAPE_EVENT, new TouchTrigger(TouchInput.KEYCODE_BACK));
app.inputManager.addListener(this, new String[]{ESCAPE_EVENT});
} }
@ -125,7 +118,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
logger.info("onDestroy"); logger.info("onDestroy");
} }
public Application getJmeApplication()
{
return app;
}
/** /**
* Called when an error has occured. This is typically * Called when an error has occured. This is typically
* invoked when an uncought exception is thrown in the render thread. * invoked when an uncought exception is thrown in the render thread.

@ -39,11 +39,13 @@ import android.opengl.GLSurfaceView;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import com.jme3.app.AndroidHarness; import com.jme3.app.AndroidHarness;
import com.jme3.app.Application;
import com.jme3.input.JoyInput; import com.jme3.input.JoyInput;
import com.jme3.input.KeyInput; import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput; import com.jme3.input.MouseInput;
import com.jme3.input.TouchInput; import com.jme3.input.TouchInput;
import com.jme3.input.android.AndroidInput; import com.jme3.input.android.AndroidInput;
import com.jme3.input.controls.TouchTrigger;
import com.jme3.input.dummy.DummyKeyInput; import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput; import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.renderer.android.OGLESShaderRenderer; import com.jme3.renderer.android.OGLESShaderRenderer;
@ -95,6 +97,8 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
*/ */
protected int clientOpenGLESVersion = 1; protected int clientOpenGLESVersion = 1;
final private String ESCAPE_EVENT = "TouchEscape";
public OGLESContext() { } public OGLESContext() { }
@Override @Override
@ -352,10 +356,21 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
renderer.setVerboseLogging(false); renderer.setVerboseLogging(false);
renderer.initialize(); renderer.initialize();
listener.initialize(); listener.initialize();
created.set(true);
// Setup exit hook
if (ctx instanceof AndroidHarness)
{
Application app = ((AndroidHarness)ctx).getJmeApplication();
if (app.getInputManager() != null)
{
app.getInputManager().addMapping(ESCAPE_EVENT, new TouchTrigger(TouchInput.KEYCODE_BACK));
app.getInputManager().addListener((AndroidHarness)ctx, new String[]{ESCAPE_EVENT});
}
}
needClose.set(false); created.set(true);
needClose.set(false);
} }
/** /**

Loading…
Cancel
Save