mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 18:02:02 +01:00
uidriver/js: Bug fix: Create goroutine for a function passed to rAF
This is necessary not to cause dead-lock. Updates #1161
This commit is contained in:
parent
a6c7c608e4
commit
be1a8bddbf
@ -184,10 +184,10 @@ func (u *UserInterface) loop(context driver.UIContext) <-chan error {
|
||||
resStopAudioCh := make(chan struct{})
|
||||
|
||||
var cf js.Func
|
||||
f := func(this js.Value, args []js.Value) interface{} {
|
||||
f := func() {
|
||||
if u.contextLost {
|
||||
requestAnimationFrame.Invoke(cf)
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
if err := u.update(); err != nil {
|
||||
@ -196,21 +196,23 @@ func (u *UserInterface) loop(context driver.UIContext) <-chan error {
|
||||
|
||||
errCh <- err
|
||||
close(errCh)
|
||||
return nil
|
||||
return
|
||||
}
|
||||
if u.vsync {
|
||||
requestAnimationFrame.Invoke(cf)
|
||||
} else {
|
||||
setTimeout.Invoke(cf, 0)
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
// TODO: Should cf be released after the game ends?
|
||||
cf = js.FuncOf(f)
|
||||
cf = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
go f()
|
||||
return nil
|
||||
})
|
||||
|
||||
// Call f asyncly to be async since ch is used in f.
|
||||
go func() {
|
||||
f(js.Value{}, nil)
|
||||
}()
|
||||
go f()
|
||||
|
||||
// Run another loop to watch suspended() as the above update function is never called when the tab is hidden.
|
||||
// To check the document's visiblity, visibilitychange event should usually be used. However, this event is
|
||||
|
Loading…
Reference in New Issue
Block a user