graphics: Bug fix: Don't delete buffers on browsers (#526)

This commit is contained in:
Hajime Hoshi 2018-03-02 01:01:27 +09:00
parent 31ff4b4535
commit 680656e6e9

View File

@ -19,6 +19,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/affine" "github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/opengl" "github.com/hajimehoshi/ebiten/internal/opengl"
"github.com/hajimehoshi/ebiten/internal/web"
) )
// arrayBufferLayoutPart is a part of an array buffer layout. // arrayBufferLayoutPart is a part of an array buffer layout.
@ -157,12 +158,17 @@ func (s *openGLState) reset() error {
if s.programLinear != zeroProgram { if s.programLinear != zeroProgram {
opengl.GetContext().DeleteProgram(s.programLinear) opengl.GetContext().DeleteProgram(s.programLinear)
} }
// On browsers (at least Chrome), buffers are already detached from the context
// and must not be deleted by DeleteBuffer.
if !web.IsBrowser() {
if s.arrayBuffer != zeroBuffer { if s.arrayBuffer != zeroBuffer {
opengl.GetContext().DeleteBuffer(s.arrayBuffer) opengl.GetContext().DeleteBuffer(s.arrayBuffer)
} }
if s.elementArrayBuffer != zeroBuffer { if s.elementArrayBuffer != zeroBuffer {
opengl.GetContext().DeleteBuffer(s.elementArrayBuffer) opengl.GetContext().DeleteBuffer(s.elementArrayBuffer)
} }
}
shaderVertexModelviewNative, err := opengl.GetContext().NewShader(opengl.VertexShader, shader(shaderVertexModelview)) shaderVertexModelviewNative, err := opengl.GetContext().NewShader(opengl.VertexShader, shader(shaderVertexModelview))
if err != nil { if err != nil {