XashActivity: implement proper engine thread quit

This commit is contained in:
Alibek Omarov (a1batross) 2017-03-04 00:21:29 +03:00
parent 7867a53895
commit 323e314714

View file

@ -241,6 +241,19 @@ public class XashActivity extends Activity {
super.onResume(); 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 @Override
public void onWindowFocusChanged(boolean hasFocus) 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 nativeBall(int id, byte ball, short xrel, short yrel);
public static native void nativeJoyAdd( int id ); public static native void nativeJoyAdd( int id );
public static native void nativeJoyDel( 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); public static native int setenv(String key, String value, boolean overwrite);
@ -624,6 +638,19 @@ View.OnKeyListener {
mEngThread.start(); mEngThread.start();
} }
} }
public void engineThreadJoin()
{
Log.v(TAG, "engineThreadJoin()");
try
{
mEngThread.join(); // wait until Xash will quit
}
catch(InterruptedException e)
{
}
}
// unused // unused
public void onDraw(Canvas canvas) {} public void onDraw(Canvas canvas) {}