Compare commits

..

2 Commits

Author SHA1 Message Date
Hajime Hoshi
a3fa7df1f3 cmd/ebitenmobile: bug fix: graceful shutdown on context lost
Closes #3097
2024-09-14 17:40:37 +09:00
Hajime Hoshi
dc5869f607 internal/ui: bug fix: InitUnfocused option didn't work
Updates #2924
Closes #3099
2024-09-14 17:36:10 +09:00
2 changed files with 12 additions and 8 deletions

View File

@ -29,13 +29,12 @@ import {{.JavaPkg}}.ebitenmobileview.RenderRequester;
import {{.JavaPkg}}.{{.PrefixLower}}.EbitenView;
class EbitenSurfaceView extends GLSurfaceView implements RenderRequester {
// As GLSurfaceView can be recreated, the states must be static (#3097).
static private boolean errored_ = false;
static private boolean onceSurfaceCreated_ = false;
static private boolean contextLost_ = false;
private class EbitenRenderer implements GLSurfaceView.Renderer {
private boolean errored_ = false;
private boolean onceSurfaceCreated_ = false;
private boolean contextLost_ = false;
@Override
public void onDrawFrame(GL10 gl) {
if (errored_) {
@ -100,7 +99,7 @@ class EbitenSurfaceView extends GLSurfaceView implements RenderRequester {
}
private void onContextLost() {
Log.v("Go", "Kill the application due to a context lost");
Log.e("Go", "The application was killed due to context loss");
// TODO: Relaunch this application for better UX (#805).
Runtime.getRuntime().exit(0);
}

View File

@ -81,6 +81,8 @@ type userInterfaceImpl struct {
initWindowMaximized bool
initWindowMousePassthrough bool
initUnfocused bool
// bufferOnceSwapped must be accessed from the main thread.
bufferOnceSwapped bool
@ -1087,6 +1089,7 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error {
return err
}
u.initUnfocused = options.InitUnfocused
focused := glfw.True
if options.InitUnfocused {
focused = glfw.False
@ -1288,9 +1291,11 @@ func (u *UserInterface) update() (float64, float64, error) {
if err = u.window.Show(); err != nil {
return
}
if !u.initUnfocused {
if err = u.window.Focus(); err != nil {
return
}
}
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
return