mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: Bug fix: AdjustPosition could return Inf
Before the initialization finishes, AdjustPosition could return Inf values and in this case AdjustPosition's returning values don't make sense. Let's return NaN in this case. Closes #1545
This commit is contained in:
parent
d415e9c771
commit
19702619ee
@ -19,6 +19,7 @@
|
||||
package glfw
|
||||
|
||||
import (
|
||||
"math"
|
||||
"sync"
|
||||
"unicode"
|
||||
|
||||
@ -307,7 +308,11 @@ func (i *Input) update(window *glfw.Window, context driver.UIContext) {
|
||||
cx = fromGLFWMonitorPixel(cx, s)
|
||||
cy = fromGLFWMonitorPixel(cy, s)
|
||||
cx, cy = context.AdjustPosition(cx, cy, s)
|
||||
i.cursorX, i.cursorY = int(cx), int(cy)
|
||||
|
||||
// AdjustPosition can return NaN at the initialization.
|
||||
if !math.IsNaN(cx) && !math.IsNaN(cy) {
|
||||
i.cursorX, i.cursorY = int(cx), int(cy)
|
||||
}
|
||||
|
||||
for id := glfw.Joystick(0); id < glfw.Joystick(len(i.gamepads)); id++ {
|
||||
i.gamepads[id].valid = false
|
||||
|
@ -235,5 +235,10 @@ func (c *uiContext) update(updateCount int) error {
|
||||
func (c *uiContext) AdjustPosition(x, y float64, deviceScaleFactor float64) (float64, float64) {
|
||||
ox, oy := c.offsets(deviceScaleFactor)
|
||||
s := c.screenScale(deviceScaleFactor)
|
||||
// The scale 0 indicates that the offscreen is not initialized yet.
|
||||
// As any cursor values don't make sense, just return NaN.
|
||||
if s == 0 {
|
||||
return math.NaN(), math.NaN()
|
||||
}
|
||||
return (x*deviceScaleFactor - ox) / s, (y*deviceScaleFactor - oy) / s
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user