mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +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{})
|
resStopAudioCh := make(chan struct{})
|
||||||
|
|
||||||
var cf js.Func
|
var cf js.Func
|
||||||
f := func(this js.Value, args []js.Value) interface{} {
|
f := func() {
|
||||||
if u.contextLost {
|
if u.contextLost {
|
||||||
requestAnimationFrame.Invoke(cf)
|
requestAnimationFrame.Invoke(cf)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := u.update(); err != nil {
|
if err := u.update(); err != nil {
|
||||||
@ -196,21 +196,23 @@ func (u *UserInterface) loop(context driver.UIContext) <-chan error {
|
|||||||
|
|
||||||
errCh <- err
|
errCh <- err
|
||||||
close(errCh)
|
close(errCh)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if u.vsync {
|
if u.vsync {
|
||||||
requestAnimationFrame.Invoke(cf)
|
requestAnimationFrame.Invoke(cf)
|
||||||
} else {
|
} else {
|
||||||
setTimeout.Invoke(cf, 0)
|
setTimeout.Invoke(cf, 0)
|
||||||
}
|
}
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
// TODO: Should cf be released after the game ends?
|
// 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.
|
// Call f asyncly to be async since ch is used in f.
|
||||||
go func() {
|
go f()
|
||||||
f(js.Value{}, nil)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Run another loop to watch suspended() as the above update function is never called when the tab is hidden.
|
// 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
|
// To check the document's visiblity, visibilitychange event should usually be used. However, this event is
|
||||||
|
Loading…
Reference in New Issue
Block a user