cmb/ebitenmobile: Define an error handler for Android

Fixes #919
This commit is contained in:
Hajime Hoshi 2019-08-18 20:22:40 +09:00
parent 876e61dd98
commit 0b1aec4d27
2 changed files with 21 additions and 7 deletions

View File

@ -212,6 +212,7 @@ package {{.JavaPkg}}.{{.PrefixLower}};
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.ViewGroup; import android.view.ViewGroup;
import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview; import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview;
@ -279,6 +280,10 @@ public class EbitenView extends ViewGroup {
} }
} }
protected void onErrorOnGameUpdate(Exception e) {
Log.e("Go", e.toString());
}
private EbitenSurfaceView ebitenSurfaceView_; private EbitenSurfaceView ebitenSurfaceView_;
private boolean initialized_ = false; private boolean initialized_ = false;
} }
@ -290,7 +295,8 @@ package {{.JavaPkg}}.{{.PrefixLower}};
import android.content.Context; import android.content.Context;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.util.Log; import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -298,10 +304,11 @@ import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview; import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview;
import {{.JavaPkg}}.{{.PrefixLower}}.EbitenView;
class EbitenSurfaceView extends GLSurfaceView { class EbitenSurfaceView extends GLSurfaceView {
private class EbitenRenderer implements Renderer { private class EbitenRenderer implements GLSurfaceView.Renderer {
private boolean errored_ = false; private boolean errored_ = false;
@ -312,10 +319,13 @@ class EbitenSurfaceView extends GLSurfaceView {
} }
try { try {
Ebitenmobileview.update(); Ebitenmobileview.update();
} catch (Exception e) { } catch (final Exception e) {
for (String line : e.toString().split("\\n")) { new Handler(Looper.getMainLooper()).post(new Runnable() {
Log.e("Go Error", line); @Override
public void run() {
onErrorOnGameUpdate(e);
} }
});
errored_ = true; errored_ = true;
} }
} }
@ -367,6 +377,10 @@ class EbitenSurfaceView extends GLSurfaceView {
return true; return true;
} }
private void onErrorOnGameUpdate(Exception e) {
((EbitenView)getParent()).onErrorOnGameUpdate(e);
}
private double deviceScale_ = 0.0; private double deviceScale_ = 0.0;
} }
` `

File diff suppressed because one or more lines are too long