diff --git a/src/in/celest/xash3d/XashActivity.java b/src/in/celest/xash3d/XashActivity.java index c5b42e73..34320033 100644 --- a/src/in/celest/xash3d/XashActivity.java +++ b/src/in/celest/xash3d/XashActivity.java @@ -241,6 +241,19 @@ public class XashActivity extends Activity { super.onResume(); } + @Override + protected void onStop() { + Log.v(TAG, "onStop()"); + + // let engine properly exit, instead of killing it's thread + nativeQuitEvent(); + // wait until Xash will exit + mSurface.engineThreadJoin(); + + + super.onStop(); + } + @Override public void onWindowFocusChanged(boolean hasFocus) { @@ -266,6 +279,7 @@ public class XashActivity extends Activity { public static native void nativeBall(int id, byte ball, short xrel, short yrel); public static native void nativeJoyAdd( int id ); public static native void nativeJoyDel( int id ); + public static native void nativeQuitEvent(); public static native int setenv(String key, String value, boolean overwrite); @@ -624,6 +638,19 @@ View.OnKeyListener { mEngThread.start(); } } + + public void engineThreadJoin() + { + Log.v(TAG, "engineThreadJoin()"); + try + { + mEngThread.join(); // wait until Xash will quit + } + catch(InterruptedException e) + { + } + + } // unused public void onDraw(Canvas canvas) {}