From 7fe96d1ba385269c5d7de8de624b123ea95ef410 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sat, 26 Nov 2016 15:51:24 +0100 Subject: [PATCH] Fixed Xlib crashing in sf::Window:setIcon because it expects the element data type passed to XChangeProperty to be unsigned long (architecture dependent 32-bit or 64-bit) instead of sf::Uint32 (architecture independent 32-bit) (#1168). Also adjusted other occurrences of wrong types passed to XChangeProperty with format set to 32. --- src/SFML/Window/Unix/WindowImplX11.cpp | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 530bea500..a17d3d312 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -777,10 +777,10 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 Uint8* iconPixels = static_cast(std::malloc(width * height * 4)); for (std::size_t i = 0; i < width * height; ++i) { - iconPixels[8 + i * 4 + 0] = pixels[i * 4 + 2]; - iconPixels[8 + i * 4 + 1] = pixels[i * 4 + 1]; - iconPixels[8 + i * 4 + 2] = pixels[i * 4 + 0]; - iconPixels[8 + i * 4 + 3] = pixels[i * 4 + 3]; + iconPixels[i * 4 + 0] = pixels[i * 4 + 2]; + iconPixels[i * 4 + 1] = pixels[i * 4 + 1]; + iconPixels[i * 4 + 2] = pixels[i * 4 + 0]; + iconPixels[i * 4 + 3] = pixels[i * 4 + 3]; } // Create the icon pixmap @@ -835,18 +835,20 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 // ICCCM wants BGRA pixels: swap red and blue channels // ICCCM also wants the first 2 unsigned 32-bit values to be width and height - std::vector icccmIconPixels(8 + width * height * 4, 0); + std::vector icccmIconPixels(2 + width * height, 0); + unsigned long* ptr = &icccmIconPixels[0]; + + *ptr++ = width; + *ptr++ = height; + for (std::size_t i = 0; i < width * height; ++i) { - icccmIconPixels[8 + i * 4 + 0] = pixels[i * 4 + 2]; - icccmIconPixels[8 + i * 4 + 1] = pixels[i * 4 + 1]; - icccmIconPixels[8 + i * 4 + 2] = pixels[i * 4 + 0]; - icccmIconPixels[8 + i * 4 + 3] = pixels[i * 4 + 3]; + *ptr++ = (pixels[i * 4 + 2] << 0 ) | + (pixels[i * 4 + 1] << 8 ) | + (pixels[i * 4 + 0] << 16) | + (pixels[i * 4 + 3] << 24); } - reinterpret_cast(&icccmIconPixels[0])[0] = width; - reinterpret_cast(&icccmIconPixels[0])[1] = height; - Atom netWmIcon = getAtom("_NET_WM_ICON"); XChangeProperty(m_display, @@ -1147,7 +1149,7 @@ void WindowImplX11::switchToFullscreen() if (netWmBypassCompositor) { - static const Uint32 bypassCompositor = 1; + static const unsigned long bypassCompositor = 1; XChangeProperty(m_display, m_window, @@ -1226,7 +1228,7 @@ void WindowImplX11::setProtocols() if (netWmPing && netWmPid) { - uint32_t pid = getpid(); + const long pid = getpid(); XChangeProperty(m_display, m_window,