Skip to content

Commit

Permalink
Update GLFW: suppress joystick issue (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Jul 14, 2021
1 parent 66dbca7 commit ec5b034
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/hajimehoshi/ebiten/v2
go 1.15

require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210714145042-ef648d7b4198
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210714155130-550f9471722b
github.com/gofrs/flock v0.8.0
github.com/hajimehoshi/bitmapfont/v2 v2.1.3
github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210714145042-ef648d7b4198 h1:ucTpB2JPNdBbIedBwFGl3p8j94ecAIYfkoYV7r3nV+E=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210714145042-ef648d7b4198/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210714155130-550f9471722b h1:WrW6EbWsK1YaFiljN7kZ91bSHcyDgLz34jZvu71yVwE=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210714155130-550f9471722b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY=
github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/hajimehoshi/bitmapfont/v2 v2.1.3 h1:JefUkL0M4nrdVwVq7MMZxSTh6mSxOylm+C4Anoucbb0=
Expand Down
8 changes: 6 additions & 2 deletions internal/glfw/glfw_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,14 @@ func GetPrimaryMonitor() *Monitor {
func Init() error {
glfwDLL.call("glfwInit")
// InvalidValue can happen when specific joysticks are used. This issue
// will be fixed in GLFW 3.3.5. As a temporary fix, accept this error.
// 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
// (#1229).
return acceptError(APIUnavailable, InvalidValue)
err := acceptError(APIUnavailable, InvalidValue)
if e, ok := err.(*glfwError); ok && e.code == InvalidValue {
return nil
}
return err
}

func (j Joystick) Present() bool {
Expand Down
20 changes: 12 additions & 8 deletions internal/glfw/load_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (e *glfwError) Error() string {

var lastErr = make(chan *glfwError, 1)

func fetchError() error {
func fetchError() *glfwError {
select {
case err := <-lastErr:
return err
Expand All @@ -146,7 +146,7 @@ func panicError() {

func flushErrors() {
if err := fetchError(); err != nil {
panic(fmt.Sprintf("glfw: uncaught error: %s", err))
panic(fmt.Sprintf("glfw: uncaught error: %s", err.Error()))
}
}

Expand All @@ -156,14 +156,18 @@ func acceptError(codes ...ErrorCode) error {
return nil
}
for _, c := range codes {
if err.(*glfwError).code == c {
return nil
if err.code == c {
return err
}
}
if err.(*glfwError).code == PlatformError {
// PlatformError is not handled here (See github.com/go-gl/glfw's implementation).
// TODO: Should we log this error?
switch err.code {
case PlatformError:
// TODO: Should we log this?
return nil
case NotInitialized, NoCurrentContext, InvalidEnum, InvalidValue, OutOfMemory:
panic(err)
default:
panic(fmt.Sprintf("glfw: uncaught error: %s", err.Error()))
}
return err
}
Expand All @@ -177,7 +181,7 @@ func goGLFWErrorCallback(code uintptr, desc *byte) uintptr {
select {
case lastErr <- err:
default:
panic(fmt.Sprintf("glfw: uncaught error: %s", err))
panic(fmt.Sprintf("glfw: uncaught error: %s", err.Error()))
}
return 0
}
Expand Down

0 comments on commit ec5b034

Please sign in to comment.