buffered: Bug fix: ebiten.Run must be called from the main thread

Updates #1027
This commit is contained in:
Hajime Hoshi 2020-02-09 04:53:21 +09:00
parent 32471af18f
commit 6250dd9f9b

View File

@ -15,6 +15,7 @@
package buffered_test package buffered_test
import ( import (
"errors"
"image/color" "image/color"
"os" "os"
"testing" "testing"
@ -34,19 +35,29 @@ func runOnMainThread(f func()) {
} }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
codeCh := make(chan int)
endCh := make(chan struct{})
go func() { go func() {
os.Exit(m.Run()) code := m.Run()
close(endCh)
codeCh <- code
close(codeCh)
}() }()
for { rt := errors.New("regular termination")
if err := ebiten.Run(func(*ebiten.Image) error { if err := ebiten.Run(func(*ebiten.Image) error {
f := <-mainCh select {
case f := <-mainCh:
f() f()
return nil case <-endCh:
}, 320, 240, 1, ""); err != nil { return rt
panic(err)
} }
return nil
}, 320, 240, 1, ""); err != nil && err != rt {
panic(err)
} }
os.Exit(<-codeCh)
} }
type testResult struct { type testResult struct {