From e5089934db850caf0a1e25c08c118db12490c55c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 2 Mar 2018 01:01:27 +0900 Subject: [PATCH] graphics: Bug fix: Don't delete buffers on browsers (#526) --- internal/graphics/program.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/graphics/program.go b/internal/graphics/program.go index 70276172a..d5a750c0f 100644 --- a/internal/graphics/program.go +++ b/internal/graphics/program.go @@ -20,6 +20,7 @@ import ( "github.com/hajimehoshi/ebiten/internal/affine" emath "github.com/hajimehoshi/ebiten/internal/math" "github.com/hajimehoshi/ebiten/internal/opengl" + "github.com/hajimehoshi/ebiten/internal/web" ) // arrayBufferLayoutPart is a part of an array buffer layout. @@ -163,11 +164,16 @@ func (s *openGLState) reset() error { if s.programScreen != zeroProgram { opengl.GetContext().DeleteProgram(s.programScreen) } - if s.arrayBuffer != zeroBuffer { - opengl.GetContext().DeleteBuffer(s.arrayBuffer) - } - if s.elementArrayBuffer != zeroBuffer { - opengl.GetContext().DeleteBuffer(s.elementArrayBuffer) + + // 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 { + opengl.GetContext().DeleteBuffer(s.arrayBuffer) + } + if s.elementArrayBuffer != zeroBuffer { + opengl.GetContext().DeleteBuffer(s.elementArrayBuffer) + } } shaderVertexModelviewNative, err := opengl.GetContext().NewShader(opengl.VertexShader, shader(shaderVertexModelview))