restorable: Do not dispose objects when restoring on browsers

This fix suppresses warnings on the Chrome console.
This commit is contained in:
Hajime Hoshi 2020-05-30 19:24:00 +09:00
parent 1042eb71e0
commit 117fd61d27
3 changed files with 47 additions and 2 deletions

View File

@ -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 {
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 {
if needsDisposingWhenRestoring {
i.image.Dispose()
}
i.image = nil
}

22
internal/restorable/js.go Normal file
View File

@ -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

View File

@ -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