From c74e7fa9433d5ae94e96657f3b03d26e303aba8d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 18 Apr 2024 13:28:51 +0900 Subject: [PATCH] internal/gamepaddb: bug fix: platform was not initialized correctly After 6552ae1dbe66d344482990cddb73f6bd0cd3062c, the order of the init function calls changed, and then the platform was not initialized correctly. This change fixes this issue by not relying on an init function to get the platform. Closes #2964 --- internal/gamepaddb/gamepaddb.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/internal/gamepaddb/gamepaddb.go b/internal/gamepaddb/gamepaddb.go index 558c9ef4d..617ea2078 100644 --- a/internal/gamepaddb/gamepaddb.go +++ b/internal/gamepaddb/gamepaddb.go @@ -39,12 +39,9 @@ const ( platformIOS ) -var currentPlatform platform - -func init() { +func currentPlatform() platform { if runtime.GOOS == "windows" { - currentPlatform = platformWindows - return + return platformWindows } if runtime.GOOS == "aix" || @@ -56,24 +53,22 @@ func init() { runtime.GOOS == "netbsd" || runtime.GOOS == "openbsd" || runtime.GOOS == "solaris" { - currentPlatform = platformUnix - return + return platformUnix } if runtime.GOOS == "android" { - currentPlatform = platformAndroid - return + return platformAndroid } if runtime.GOOS == "ios" { - currentPlatform = platformIOS - return + return platformIOS } if runtime.GOOS == "darwin" { - currentPlatform = platformMacOS - return + return platformMacOS } + + return platformUnknown } type mappingType int @@ -336,7 +331,7 @@ func buttonMappings(id string) map[StandardButton]mapping { if m, ok := gamepadButtonMappings[id]; ok { return m } - if currentPlatform == platformAndroid { + if currentPlatform() == platformAndroid { if addAndroidDefaultMappings(id) { return gamepadButtonMappings[id] } @@ -348,7 +343,7 @@ func axisMappings(id string) map[StandardAxis]mapping { if m, ok := gamepadAxisMappings[id]; ok { return m } - if currentPlatform == platformAndroid { + if currentPlatform() == platformAndroid { if addAndroidDefaultMappings(id) { return gamepadAxisMappings[id] } @@ -544,7 +539,7 @@ func Update(mappingData []byte) error { for s.Scan() { line := s.Text() - id, name, buttons, axes, err := parseLine(line, currentPlatform) + id, name, buttons, axes, err := parseLine(line, currentPlatform()) if err != nil { return err }