From 117fd61d27d9b8c63b807ac13fde79ddb9d2fa20 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 30 May 2020 19:24:00 +0900 Subject: [PATCH] restorable: Do not dispose objects when restoring on browsers This fix suppresses warnings on the Chrome console. --- internal/restorable/images.go | 8 ++++++-- internal/restorable/js.go | 22 ++++++++++++++++++++++ internal/restorable/notjs.go | 19 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 internal/restorable/js.go create mode 100644 internal/restorable/notjs.go diff --git a/internal/restorable/images.go b/internal/restorable/images.go index b7d45b69c..4ffaeac41 100644 --- a/internal/restorable/images.go +++ b/internal/restorable/images.go @@ -183,7 +183,9 @@ func (i *images) restore() error { // Dispose all the shaders ahead of restoring. A current shader ID and a new shader ID can be duplicated. for s := range i.shaders { - s.shader.Dispose() + if needsDisposingWhenRestoring { + s.shader.Dispose() + } s.shader = nil } for s := range i.shaders { @@ -193,7 +195,9 @@ func (i *images) restore() error { // Dispose all the images ahead of restoring. A current texture ID and a new texture ID can be duplicated. // TODO: Write a test to confirm that ID duplication never happens. for i := range i.images { - i.image.Dispose() + if needsDisposingWhenRestoring { + i.image.Dispose() + } i.image = nil } diff --git a/internal/restorable/js.go b/internal/restorable/js.go new file mode 100644 index 000000000..8a14cda21 --- /dev/null +++ b/internal/restorable/js.go @@ -0,0 +1,22 @@ +// 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. + +// +build js + +package restorable + +// On browsers, disposing resources is not required since the objects are already managed by JavaScript GC and they +// are already invalidated. Rather, disposing them when restoring causes warnings on the console. + +const needsDisposingWhenRestoring = false diff --git a/internal/restorable/notjs.go b/internal/restorable/notjs.go new file mode 100644 index 000000000..b5989c031 --- /dev/null +++ b/internal/restorable/notjs.go @@ -0,0 +1,19 @@ +// 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. + +// +build !js + +package restorable + +const needsDisposingWhenRestoring = true