mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/graphicsdriver/opengl: Bug fix: A location cache map must be reset when a program is deleted
Closes #1753
This commit is contained in:
parent
57a2db982b
commit
6efc01b7ab
@ -309,6 +309,8 @@ func (c *context) useProgram(p program) {
|
||||
}
|
||||
|
||||
func (c *context) deleteProgram(p program) {
|
||||
c.locationCache.deleteProgram(p)
|
||||
|
||||
if !gl.IsProgram(uint32(p)) {
|
||||
return
|
||||
}
|
||||
|
@ -367,6 +367,8 @@ func (c *context) useProgram(p program) {
|
||||
}
|
||||
|
||||
func (c *context) deleteProgram(p program) {
|
||||
c.locationCache.deleteProgram(p)
|
||||
|
||||
gl := c.gl
|
||||
if !gl.isProgram.Invoke(p.value).Bool() {
|
||||
return
|
||||
|
@ -282,6 +282,8 @@ func (c *context) useProgram(p program) {
|
||||
}
|
||||
|
||||
func (c *context) deleteProgram(p program) {
|
||||
c.locationCache.deleteProgram(p)
|
||||
|
||||
if !c.ctx.IsProgram(uint32(p)) {
|
||||
return
|
||||
}
|
||||
|
@ -38,3 +38,7 @@ func (c *locationCache) GetUniformLocation(context *context, p program, location
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func (c *locationCache) deleteProgram(p program) {
|
||||
delete(c.uniformLocationCache, getProgramID(p))
|
||||
}
|
||||
|
54
internal/processtest/processtest_test.go
Normal file
54
internal/processtest/processtest_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright 2021 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
|
||||
// +build !android,!js,!ios
|
||||
|
||||
package processtest_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
dir := "testdata"
|
||||
ents, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, e := range ents {
|
||||
if e.IsDir() {
|
||||
continue
|
||||
}
|
||||
n := e.Name()
|
||||
if !strings.HasSuffix(n, ".go") {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(n, func(t *testing.T) {
|
||||
cmd := exec.Command("go", "run", filepath.Join(dir, n))
|
||||
stderr := &bytes.Buffer{}
|
||||
cmd.Stderr = stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Errorf("%v\n%s", err, stderr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
114
internal/processtest/testdata/issue1753.go
vendored
Normal file
114
internal/processtest/testdata/issue1753.go
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
// Copyright 2021 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 ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"image/color"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
var regularTermination = errors.New("regular termination")
|
||||
|
||||
type Game struct {
|
||||
dst *ebiten.Image
|
||||
phase int
|
||||
}
|
||||
|
||||
func (g *Game) Update() error {
|
||||
const w, h = 1, 1
|
||||
|
||||
switch g.phase {
|
||||
case 0:
|
||||
s, err := ebiten.NewShader([]byte(`package main
|
||||
|
||||
var Color vec4
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
return Color
|
||||
}`))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
g.dst = ebiten.NewImage(w, h)
|
||||
|
||||
op := &ebiten.DrawRectShaderOptions{}
|
||||
op.CompositeMode = ebiten.CompositeModeCopy
|
||||
op.Uniforms = map[string]interface{}{
|
||||
"Color": []float32{1, 1, 1, 1},
|
||||
}
|
||||
g.dst.DrawRectShader(w, h, s, op)
|
||||
if got, want := g.dst.At(0, 0), (color.RGBA{0xff, 0xff, 0xff, 0xff}); got != want {
|
||||
return fmt.Errorf("phase: %d, got: %v, want: %v", g.phase, got, want)
|
||||
}
|
||||
|
||||
// Dispose the shader. When a new shader is created in the next phase, the underlying shader ID might be reused.
|
||||
// This test checks that the new shader works in this situation.
|
||||
// The actual disposal will happen after this frame and before the next frame in the current implmentation.
|
||||
s.Dispose()
|
||||
|
||||
g.phase++
|
||||
|
||||
case 1:
|
||||
s, err := ebiten.NewShader([]byte(`package main
|
||||
|
||||
var Dummy float
|
||||
var A, B, G, R float
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
return vec4(R, G, B, A)
|
||||
}`))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
op := &ebiten.DrawRectShaderOptions{}
|
||||
op.CompositeMode = ebiten.CompositeModeCopy
|
||||
op.Uniforms = map[string]interface{}{
|
||||
"Dummy": float32(0),
|
||||
"R": float32(0.5),
|
||||
"G": float32(1),
|
||||
"B": float32(0.5),
|
||||
"A": float32(1),
|
||||
}
|
||||
g.dst.DrawRectShader(w, h, s, op)
|
||||
if got, want := g.dst.At(0, 0), (color.RGBA{0x80, 0xff, 0x80, 0xff}); got != want {
|
||||
return fmt.Errorf("phase: %d, got: %v, want: %v", g.phase, got, want)
|
||||
}
|
||||
|
||||
return regularTermination
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Game) Draw(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
func (g *Game) Layout(width, height int) (int, int) {
|
||||
return width, height
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user