Closed dpeckham closed 4 years ago
Hi @dpeckham, did you manage to solve this issue?
@dpeckham I'd like to know as well, any solution? I'm seeing this happen on Mojave, but not on Catalina and I'm a little confused.
Hi @nathan-fiscaletti, would you be able to provide me with a minimal code that reproduces the issue? I have two Macbooks which run Mojave and Catalina so I can test this and hopefully find the issue!
@veeableful
I'm seeing it happen on Catalina now as well. After some more testing, I've been able to discover that for some reason, my canvas is not the same size as the initial values i had originally passed to sdlcanvas.CreateWindow()
.
Here is some sample code.
package main
import(
"fmt"
"github.com/tfriedel6/canvas"
"github.com/tfriedel6/canvas/sdlcanvas"
"github.com/tfriedel6/canvas/backend/softwarebackend"
)
func main() {
// The size i would like my window to be
screenW := 1600
screenH := 900
// The size i would like the draggable square in the center to be.
squareSize := 128
wnd, cv, err := sdlcanvas.CreateWindow(screenW, screenH, "Example")
if err != nil {
panic(err)
}
fmt.Printf("Desired: %v w x %v h\n", screenW, screenH)
fmt.Printf("Actual: %v w x %v h\n", cv.Width(), cv.Height())
// Create a square. This square will be displayed in the center
// of the window and should be draggable.
backend := softwarebackend.New(squareSize, squareSize)
cvImg := canvas.New(backend)
cvImg.SetFillStyle("#FFF")
cvImg.Rect(0, 0, 64, 64)
cvImg.Fill()
img := cvImg.GetImageData(0, 0, squareSize, squareSize)
// Load the square into the main canvas as an image.
imgFinal, err := cv.LoadImage(img)
if err != nil {
panic(err)
}
// Starting position for the square
xStartPos := (screenW / 2) - (squareSize / 2)
yStartPos := (screenH / 2) - (squareSize / 2)
// Active position for the square
xPos := xStartPos
yPos := yStartPos
// Basic properties for tracking the cursor
followMouse := false
// When the mouse is released, stop following it and
// snap the square back to it's original pos.
wnd.MouseUp = func(b, x, y int) {
followMouse = false
xPos = xStartPos
yPos = yStartPos
}
// Only begin following the cursor if the square is clicked.
wnd.MouseDown = func(b, x, y int) {
if x > xStartPos && x < xStartPos + squareSize {
if y > yStartPos && y < yStartPos + squareSize {
followMouse = true
}
}
}
// When the mouse is moved, if we should be following the cursor
// update the location of the square to match that of the cursor.
wnd.MouseMove = func(x, y int) {
if followMouse {
xPos = x - (squareSize / 2)
yPos = y - (squareSize / 2)
}
}
defer wnd.Destroy()
// Start the main loop for rendering.
wnd.MainLoop(func() {
// I've been able to determine that for some reason, my canvas
// is not the same size as the initial values i had originally
// passed to sdlcanvas.CreateWindow().
// This seems to properly fill the entire canvas
w, h := float64(cv.Width()), float64(cv.Height())
cv.SetFillStyle("#fff")
cv.FillRect(0, 0, w, h)
// This does not fill the entire canvas.
w2, h2 := float64(screenW), float64(screenH)
cv.SetFillStyle("#000")
cv.FillRect(0, 0, w2, h2)
// This should be in the center of the window when it is first
// spawned but instead is is in the center of the top left
// quadrant of the window, which happens to be the center of
// the true canvas.
cv.DrawImage(imgFinal, float64(xPos),
float64(yPos),
float64(squareSize),
float64(squareSize))
})
}
When I run it, I get this output:
$ go run main.go
Desired: 1600 w x 900 h
Actual: 3200 w x 1800 h
I'm wondering if this has something to do with macOS' scaling features?
--
After doing some more testing, I've found that if I change my display to "default for display", I get a different "actual" value.
Desired: 1600 w x 900 h
Actual: 2048 w x 1090 h
I'm confident now that this has at least something to do with macOS' scaling features.
This testing was all done on a Late 2015 Mac Book Pro.
And I'm just now realizing this issue is in a dependant library of the one I'm using. So the issue may be in the higher level library, but it could be here. I really don't know :( it does sound somewhat like @dpeckham was experiencing something similar though.
Hi @nathan-fiscaletti, I discovered that you can disable the high DPI scaling by setting the SDL2 hint like below:
sdl.SetHint(sdl.HINT_VIDEO_HIGHDPI_DISABLED, "1")
before creating your window. Would this help?
Hi @nathan-fiscaletti, I discovered that you can disable the high DPI scaling by setting the SDL2 hint like below:
sdl.SetHint(sdl.HINT_VIDEO_HIGHDPI_DISABLED, "1")
before creating your window. Would this help?
That seems to fix it!
Until upgrading to macOS Catalina, my app has been running fine. It's 768x1024 and runs properly on Linux, MacOS, and on an ARM/Linux embedded device.
However, after upgrading to MacOS Catalina, almost all of the content is not rendering. See the attached images. With SDL2 2.0.10 installed, the app is the proper dimensions, but is missing content.
So, I tried rolling back to an older version of SDL2, version 2.0.9. With that version installed, all the content is rendered in a 768x1024 window, but is scaled to 25% size. Quite strange.
Oddly, the go-sdl2-examples (text.go and render.go) seem to be working fine using the macOS Catalina versions. I have run the examples on Linux and this Mac with identical results.
Any ideas where to start looking? I have ensured that I rolled back my app to a stable working version.
$ cat go.mod module github.com/dpeckham/roadbook go 1.12 require ( github.com/brian-armstrong/gpio v0.0.0-20181227042754-72b0058bbbcb github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/pkg/errors v0.8.1 github.com/sirupsen/logrus v1.4.2 github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9 github.com/stretchr/testify v1.2.2 github.com/veandco/go-sdl2 v0.4.0-rc.0 github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de )
$ cat go.sum github.com/brian-armstrong/gpio v0.0.0-20181227042754-72b0058bbbcb h1:VmtJv/dx6i7ze0RWn6iXfRyTEFdgK06+7elSCYec4Fg= github.com/brian-armstrong/gpio v0.0.0-20181227042754-72b0058bbbcb/go.mod h1:akEYRl6/10JSSoNEyjgoLKKrw1M8+uBh5xsQQzxXvHs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4 h1:G2ztCwXov8mRvP0ZfjE6nAlaCX2XbykaeHdbT6KwDz0= github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4/go.mod h1:2RvX5ZjVtsznNZPEt4xwJXNJrM3VTZoQf7V6gk0ysvs= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9 h1:lpEzuenPuO1XNTeikEmvqYFcU37GVLl8SRNblzyvGBE= github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/veandco/go-sdl2 v0.3.3 h1:4/TirgB2MQ7oww3pM3Yfgf1YbChMlAQAmiCPe5koK0I= github.com/veandco/go-sdl2 v0.3.3/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg= github.com/veandco/go-sdl2 v0.4.0-rc.0 h1:SIODraeABIGQy1wULFpNp1gJhxhSCFsEAIYACxaPZQU= github.com/veandco/go-sdl2 v0.4.0-rc.0/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg= github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de h1:fkw+7JkxF3U1GzQoX9h69Wvtvxajo5Rbzy6+YMMzPIg= github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
LINUX VERSIONS
$ apt list --installed | grep -i sdl
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libsdl1.2-dev/bionic-updates,bionic-security,now 1.2.15+dfsg2-0.1ubuntu0.1 amd64 [installed] libsdl1.2debian/bionic-updates,bionic-security,now 1.2.15+dfsg2-0.1ubuntu0.1 amd64 [installed,automatic] libsdl2-2.0-0/bionic-updates,bionic-security,now 2.0.8+dfsg1-1ubuntu1.18.04.4 amd64 [installed,automatic] libsdl2-dev/bionic-updates,bionic-security,now 2.0.8+dfsg1-1ubuntu1.18.04.4 amd64 [installed] libsdl2-gfx-1.0-0/bionic,now 1.0.4+dfsg-1 amd64 [installed,automatic] libsdl2-gfx-dev/bionic,now 1.0.4+dfsg-1 amd64 [installed] libsdl2-image-2.0-0/bionic,now 2.0.3+dfsg1-1 amd64 [installed] libsdl2-image-dev/bionic,now 2.0.3+dfsg1-1 amd64 [installed] libsdl2-mixer-2.0-0/bionic,now 2.0.2+dfsg1-2 amd64 [installed] libsdl2-mixer-dev/bionic,now 2.0.2+dfsg1-2 amd64 [installed] libsdl2-ttf-2.0-0/bionic,now 2.0.14+dfsg1-2 amd64 [installed] libsdl2-ttf-dev/bionic,now 2.0.14+dfsg1-2 amd64 [installed]
MAC VERSIONS (Linux versions are below this)
$ brew list --versions freetype 2.10.1 gettext 0.20.1 git 2.23.0_1 jpeg 9c libmodplug 0.8.9.0 libogg 1.3.4 libpng 1.6.37 libtiff 4.0.10_1 libvorbis 1.3.6 pcre2 10.33 pkg-config 0.29.2 sdl2 2.0.10 sdl2_gfx 1.0.4 sdl2_image 2.0.5 sdl2_mixer 2.0.4 sdl2_ttf 2.0.15 webp 1.0.3