Skip to content

Commit

Permalink
internal/uidriver/glfw: Bug fix: Deadlock at FramebufferSize callback
Browse files Browse the repository at this point in the history
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 hajimehoshi#1618
  • Loading branch information
hajimehoshi committed Apr 23, 2021
1 parent f5574d9 commit 3e4b65d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/uidriver/glfw/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3e4b65d

Please sign in to comment.