mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
graphicsdriver/glfw: Bug fix: CPU was busy when the window is hidden
Fixes #982
This commit is contained in:
parent
8c54cf639a
commit
bfd5774faf
@ -823,6 +823,13 @@ func (u *UserInterface) loop(context driver.UIContext) error {
|
||||
})
|
||||
}()
|
||||
for {
|
||||
unfocused := u.window.GetAttrib(glfw.Focused) == glfw.False
|
||||
|
||||
var t1, t2 time.Time
|
||||
|
||||
if unfocused {
|
||||
t1 = time.Now()
|
||||
}
|
||||
if err := u.update(context); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -831,6 +838,19 @@ func (u *UserInterface) loop(context driver.UIContext) error {
|
||||
u.swapBuffers()
|
||||
return nil
|
||||
})
|
||||
if unfocused {
|
||||
t2 = time.Now()
|
||||
}
|
||||
|
||||
// When a window is not focused, SwapBuffers might return immediately and CPU might be busy.
|
||||
// Mitigate this by sleeping (#982).
|
||||
if unfocused {
|
||||
d := t2.Sub(t1)
|
||||
const wait = time.Second / 60
|
||||
if d < wait {
|
||||
time.Sleep(wait - d)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user