Skip to content

Commit

Permalink
Ignore invalidValue at PollEvents, WaitEvents, and WaitEventsTimeout (#…
Browse files Browse the repository at this point in the history
…327)

This error happens when a joystick is connected while the application
is running.

Closes #324
Updates #292
  • Loading branch information
hajimehoshi authored Jul 15, 2021
1 parent 550f947 commit ab62978
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions v3.3/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,21 @@ func (w *Window) GetClipboardString() string {
return C.GoString(cs)
}

// panicErrorExceptForInvalidValue is the same as panicError but ignores
// invalidValue.
func panicErrorExceptForInvalidValue() {
// invalidValue can happen when specific joysticks are used. This issue
// will be fixed in GLFW 3.3.5. As a temporary fix, ignore this error.
// See go-gl/glfw#292, go-gl/glfw#324, and glfw/glfw#1763.
err := acceptError(invalidValue)
if e, ok := err.(*Error); ok && e.Code == invalidValue {
return
}
if err != nil {
panic(err)
}
}

// PollEvents processes only those events that have already been received and
// then returns immediately. Processing events will cause the window and input
// callbacks associated with those events to be called.
Expand All @@ -947,7 +962,7 @@ func (w *Window) GetClipboardString() string {
// This function may only be called from the main thread.
func PollEvents() {
C.glfwPollEvents()
panicError()
panicErrorExceptForInvalidValue()
}

// WaitEvents puts the calling thread to sleep until at least one event has been
Expand All @@ -965,7 +980,7 @@ func PollEvents() {
// This function may only be called from the main thread.
func WaitEvents() {
C.glfwWaitEvents()
panicError()
panicErrorExceptForInvalidValue()
}

// WaitEventsTimeout puts the calling thread to sleep until at least one event is available in the
Expand All @@ -992,7 +1007,7 @@ func WaitEvents() {
// Event processing is not required for joystick input to work.
func WaitEventsTimeout(timeout float64) {
C.glfwWaitEventsTimeout(C.double(timeout))
panicError()
panicErrorExceptForInvalidValue()
}

// PostEmptyEvent posts an empty event from the current thread to the main
Expand Down

0 comments on commit ab62978

Please sign in to comment.