internal/uidriver/glfw: Bug fix: Deadlock at FramebufferSize callback

glfw.PollEvents might invoke multiple FramebufferSize callbacks in
theory, this is very rare though. In this case, the sending an object
to the channel never ends.

This change fixes this deadlock by using 'select'.

Closes #1618
This commit is contained in:
Hajime Hoshi 2021-04-24 02:19:00 +09:00
parent f5574d911e
commit 3e4b65d35a

View File

@ -1039,7 +1039,12 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) {
if oldW != newW || oldH != newH {
ch := make(chan struct{}, 1)
u.window.SetFramebufferSizeCallback(func(_ *glfw.Window, _, _ int) {
ch <- struct{}{}
// This callback can be invoked multiple times by one PollEvents in theory (#1618).
// Allow the case when the channel is full.
select {
case ch <- struct{}{}:
default:
}
})
u.window.SetSize(newW, newH)
// Just after SetSize, GetSize is not reliable especially on Linux/UNIX.