mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +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
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user