mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
internal/uidriver/glfw: Bug fix: Potential crash when xgb.NewConn fails
This commit is contained in:
parent
65c2fd4bcd
commit
0ac4c7323f
@ -58,34 +58,35 @@ func videoModeScale(m *glfw.Monitor) float64 {
|
||||
|
||||
// videoModeScaleUncached must be called from the main thread.
|
||||
func videoModeScaleUncached(m *glfw.Monitor, monitorX, monitorY int) float64 {
|
||||
// TODO: if https://github.com/glfw/glfw/issues/1961 gets fixed, this function may need revising.
|
||||
// TODO: if glfw/glfw#1961 gets fixed, this function may need revising.
|
||||
// In case GLFW decides to switch to returning logical pixels, we can just return 1.
|
||||
|
||||
// Note: GLFW currently returns physical pixel sizes,
|
||||
// but we need to predict the window system-side size of the fullscreen window
|
||||
// for our `ScreenSizeInFullscreen` public API.
|
||||
// for Ebiten's `ScreenSizeInFullscreen` public API.
|
||||
// Also at the moment we need this prior to switching to fullscreen, but that might be replacable.
|
||||
// So this function computes the ratio of physical per logical pixels.
|
||||
xconn, err := xgb.NewConn()
|
||||
defer xconn.Close()
|
||||
if err != nil {
|
||||
// No X11 connection?
|
||||
// Assume we're on pure Wayland then.
|
||||
// GLFW/Wayland shouldn't be having this issue.
|
||||
return 1
|
||||
}
|
||||
defer xconn.Close()
|
||||
|
||||
if err = randr.Init(xconn); err != nil {
|
||||
// No RANDR extension?
|
||||
// No problem.
|
||||
// No RANDR extension? No problem.
|
||||
return 1
|
||||
}
|
||||
|
||||
root := xproto.Setup(xconn).DefaultScreen(xconn).Root
|
||||
res, err := randr.GetScreenResourcesCurrent(xconn, root).Reply()
|
||||
if err != nil {
|
||||
// Likely means RANDR is not working.
|
||||
// No problem.
|
||||
// Likely means RANDR is not working. No problem.
|
||||
return 1
|
||||
}
|
||||
|
||||
for _, crtc := range res.Crtcs[:res.NumCrtcs] {
|
||||
info, err := randr.GetCrtcInfo(xconn, crtc, res.ConfigTimestamp).Reply()
|
||||
if err != nil {
|
||||
@ -107,6 +108,7 @@ func videoModeScaleUncached(m *glfw.Monitor, monitorX, monitorY int) float64 {
|
||||
return scale
|
||||
}
|
||||
}
|
||||
|
||||
// Monitor not known to XRandR. Weird.
|
||||
return 1
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user