diff --git a/internal/restorable/const_gles.go b/internal/restorable/const_gles.go deleted file mode 100644 index 9b8dcd35a..000000000 --- a/internal/restorable/const_gles.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2020 The Ebiten Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build android || (ios && ebitengl) -// +build android ios,ebitengl - -package restorable - -const canDetectContextLostExplicitly = true diff --git a/internal/restorable/const_js.go b/internal/restorable/const_js.go deleted file mode 100644 index 71de15d31..000000000 --- a/internal/restorable/const_js.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2020 The Ebiten Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package restorable - -// canDetectContextLostExplicitly reports whether the context lost can be detected by handlers in an explicit way. -const canDetectContextLostExplicitly = true diff --git a/internal/restorable/const_others.go b/internal/restorable/const_others.go deleted file mode 100644 index 90c07cb79..000000000 --- a/internal/restorable/const_others.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2020 The Ebiten Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !android && !js && (!ios || !ebitengl) -// +build !android -// +build !js -// +build !ios !ebitengl - -package restorable - -const canDetectContextLostExplicitly = false diff --git a/internal/restorable/images.go b/internal/restorable/images.go index 218dc060a..0601df01c 100644 --- a/internal/restorable/images.go +++ b/internal/restorable/images.go @@ -17,6 +17,7 @@ package restorable import ( "image" "path/filepath" + "runtime" "github.com/hajimehoshi/ebiten/v2/internal/debug" "github.com/hajimehoshi/ebiten/v2/internal/graphicscommand" @@ -292,8 +293,11 @@ func MaxImageSize(graphicsDriver graphicsdriver.Graphics) int { // OnContextLost is called when the context lost is detected in an explicit way. func OnContextLost() { - if !canDetectContextLostExplicitly { - panic("restorable: OnContextLost cannot be called in this environment") - } + canDetectContextLostExplicitly = true theImages.contextLost = true } + +// canDetectContextLostExplicitly reports whether Ebiten can detect a context lost in an explicit way. +// On Android, a context lost can be detected via GLSurfaceView.Renderer.onSurfaceCreated. +// On iOS w/ OpenGL ES, this can be detected only when gomobile-build is used. +var canDetectContextLostExplicitly = runtime.GOOS == "android"