ebiten/internal/processtest/testdata/issue2815.go
Hajime Hoshi ad51e22252 internal/atlas: bug fix: ReadPixels crashed when inFrame was false
This change fixes the issue by letting ReadPixels return a channel
and executing this asynchronously when needed.

Closes #2815
2023-10-19 03:56:54 +09:00

73 lines
1.4 KiB
Go

// Copyright 2023 The Ebitengine 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
package main
import (
"time"
"github.com/hajimehoshi/ebiten/v2"
)
type Game struct {
init bool
count int
end0 chan struct{}
end1 chan struct{}
}
func (g *Game) Update() error {
if !g.init {
g.end0 = make(chan struct{})
g.end1 = make(chan struct{})
img := ebiten.NewImage(1, 1)
go func() {
t := time.Tick(time.Microsecond)
loop:
for {
select {
case <-t:
img.At(0, 0)
case <-g.end0:
close(g.end1)
break loop
}
}
}()
g.init = true
}
g.count++
if g.count >= 60 {
close(g.end0)
<-g.end1
return ebiten.Termination
}
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
}
func (g *Game) Layout(w, h int) (int, int) {
return 320, 240
}
func main() {
if err := ebiten.RunGame(&Game{}); err != nil {
panic(err)
}
}