mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
buffered: Bug fix: ebiten.Run must be called from the main thread
Updates #1027
This commit is contained in:
parent
32471af18f
commit
6250dd9f9b
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user