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