Fix intermittent surface crash on exit

This commit is contained in:
Arnaud Brochard 2022-11-02 22:04:30 +01:00
parent d10ac46405
commit c208d9f31a
2 changed files with 13 additions and 3 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.ab.x48" android:installLocation="auto" android:versionCode="76" android:versionName="1.76">
package="org.ab.x48" android:installLocation="auto" android:versionCode="77" android:versionName="1.77">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".X48"
android:label="@string/app_name"

View file

@ -34,6 +34,7 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
public class HPView extends SurfaceView implements SurfaceHolder.Callback {
@ -42,6 +43,7 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback {
private Bitmap mainScreen;
private SurfaceHolder mSurfaceHolder;
private boolean surfaceValid;
private int visibility = VISIBLE;
private Bitmap annImages [];
private Bitmap menuIcon;
boolean ann [];
@ -945,6 +947,12 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback {
//Log.i("x48", "data: " + data.length);
}
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
this.visibility = visibility;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
synchronized (mSurfaceHolder) {
@ -1072,7 +1080,9 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback {
else
currentOrientation = Configuration.ORIENTATION_LANDSCAPE;
//initGraphicsElements();
synchronized (mSurfaceHolder) {
backBuffer = null;
}
x48.flipScreen();
}
@ -1116,7 +1126,7 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback {
}
public void refresh() {
if (surfaceValid) {
if (surfaceValid && visibility == VISIBLE) {
if (needFlip || x48.fillScreenData(buf, ann) == 1) {
needFlip = false;
refreshMainScreen(buf);