ebiten: remove RunOnMainThread

Unfortunately, there are several issues in RunOnMainThread:

 * RunOnMainThread cannot be portable: It is impossible to implement this
   correctly on mobiles.
 * RunOnMainThread doesn't make sense on mobiles: the rendering works on
   a different thread (goroutine) on mobiles.
 * RunOnMainThread can cause deadlocks very easily.

Until we find a better solution, let's remove this.

Closes #1945
This commit is contained in:
Hajime Hoshi 2022-02-14 01:49:39 +09:00
parent e09c1bf8f1
commit fcd4453e4f
3 changed files with 6 additions and 12 deletions

View File

@ -225,7 +225,7 @@ func (q *commandQueue) Enqueue(command command) {
// Flush flushes the command queue.
func (q *commandQueue) Flush() (err error) {
RunOnRenderingThread(func() {
runOnRenderingThread(func() {
err = q.flush()
})
return
@ -701,7 +701,7 @@ func (c *newShaderCommand) Exec(indexOffset int) error {
// InitializeGraphicsDriverState initialize the current graphics driver state.
func InitializeGraphicsDriverState() (err error) {
RunOnRenderingThread(func() {
runOnRenderingThread(func() {
err = theGraphicsDriver.Initialize()
})
return
@ -711,7 +711,7 @@ func InitializeGraphicsDriverState() (err error) {
// If the graphics driver doesn't have an API to reset, ResetGraphicsDriverState does nothing.
func ResetGraphicsDriverState() (err error) {
if r, ok := theGraphicsDriver.(interface{ Reset() error }); ok {
RunOnRenderingThread(func() {
runOnRenderingThread(func() {
err = r.Reset()
})
}
@ -721,7 +721,7 @@ func ResetGraphicsDriverState() (err error) {
// MaxImageSize returns the maximum size of an image.
func MaxImageSize() int {
var size int
RunOnRenderingThread(func() {
runOnRenderingThread(func() {
size = theGraphicsDriver.MaxImageSize()
})
return size

View File

@ -25,8 +25,8 @@ func SetRenderingThread(thread Thread) {
theThread = thread
}
// RunOnRenderingThread calls f on the rendering thread, and returns an error if any.
func RunOnRenderingThread(f func()) {
// runOnRenderingThread calls f on the rendering thread, and returns an error if any.
func runOnRenderingThread(f func()) {
// The thread is nil when 1) GOOS=js or 2) using golang.org/x/mobile/gl.
// When golang.org/x/mobile/gl is used, all the GL functions are called via Context, which already runs on an
// appropriate thread.

6
run.go
View File

@ -18,7 +18,6 @@ import (
"sync/atomic"
"github.com/hajimehoshi/ebiten/v2/internal/clock"
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/v2/internal/ui"
)
@ -162,11 +161,6 @@ func RunGame(game Game) error {
return nil
}
// RunOnMainThread calls the given f on the main thread, and blocks until f returns.
func RunOnMainThread(f func()) {
graphicscommand.RunOnRenderingThread(f)
}
func isRunGameEnded() bool {
return atomic.LoadInt32(&isRunGameEnded_) != 0
}