Skip to content

Commit b0d5bc9

Browse files
committed
Ignore invalidValue at PollEvents, WaitEvents, and WaitEventsTimeout
This error happens when a joystick is connected while the application is running. Closes #324 Updates #292
1 parent 550f947 commit b0d5bc9

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

v3.3/glfw/window.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,21 @@ func (w *Window) GetClipboardString() string {
936936
return C.GoString(cs)
937937
}
938938

939+
// panicErrorExceptForInvalidValue is the same as panicError but ignores
940+
// invalidValue.
941+
func panicErrorExceptForInvalidValue() {
942+
// invalidValue can happen when specific joysticks are used. This issue
943+
// will be fixed in GLFW 3.3.5. As a temporary fix, ignore this error.
944+
// See go-gl/glfw#292, go-gl/glfw#324, and glfw/glfw#1763.
945+
err := acceptError(invalidValue)
946+
if e, ok := err.(*Error); ok && e.Code == invalidValue {
947+
return
948+
}
949+
if err != nil {
950+
panic(err)
951+
}
952+
}
953+
939954
// PollEvents processes only those events that have already been received and
940955
// then returns immediately. Processing events will cause the window and input
941956
// callbacks associated with those events to be called.
@@ -947,7 +962,7 @@ func (w *Window) GetClipboardString() string {
947962
// This function may only be called from the main thread.
948963
func PollEvents() {
949964
C.glfwPollEvents()
950-
panicError()
965+
panicErrorExceptForInvalidValue()
951966
}
952967

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

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

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

0 commit comments

Comments
 (0)