Skip to content

Commit 1cfccc3

Browse files
authored
Default to X11 as GLFW_PLATFORM on Linux to avoid (#74)
* Default to `X11` as `GLFW_PLATFORM` on Linux to avoid Wayland/libdecor ASAN leak which causes unresponsiveness. See issue #68 #68 Summary: ASAN reports leaks seemingly from the Wayland setup or decoration stack (libdecor/GTK/Pango/Fontconfig via GLFW) that persist until process exit. This does not seem to be related to render/present stalls; override with GLFW_PLATFORM if you explicitly want Wayland. Maybe it can work with Wayland at some point * `glfw` `3.4` (#75) it is required for the window hints * turn off wayland for now
1 parent c8bd5d9 commit 1cfccc3

File tree

6 files changed

+83
-5
lines changed

6 files changed

+83
-5
lines changed

.github/workflows/linux-smoke-tests.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,24 @@ jobs:
3838
sudo apt-get install -y \
3939
build-essential cmake ninja-build \
4040
libgtest-dev libspdlog-dev \
41-
libglfw3 libglfw3-dev libvulkan-dev \
41+
libvulkan-dev \
4242
glslang-tools glslang-dev libglm-dev \
4343
mesa-vulkan-drivers xvfb pkg-config \
44+
libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev \
4445
libavcodec-dev libavformat-dev libavutil-dev libswscale-dev
4546
47+
- name: Build and install GLFW 3.4 (Linux X11 platform hints required)
48+
run: |
49+
git clone --depth 1 --branch 3.4 https://github.com/glfw/glfw.git /tmp/glfw
50+
# Build X11-only to avoid Wayland issue
51+
# See issue #68: https://github.com/jamylak/vsdf/issues/68
52+
cmake -S /tmp/glfw -B /tmp/glfw/build -G Ninja \
53+
-DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF \
54+
-DGLFW_BUILD_DOCS=OFF -DGLFW_INSTALL=ON \
55+
-DGLFW_BUILD_WAYLAND=OFF
56+
cmake --build /tmp/glfw/build
57+
sudo cmake --install /tmp/glfw/build
58+
4659
- name: Configure
4760
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON -DBUILD_TESTS=ON -G Ninja .
4861

.github/workflows/release.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@ jobs:
2626
sudo apt-get install -y --no-install-recommends \
2727
build-essential cmake ninja-build \
2828
libspdlog-dev \
29-
libglfw3 libglfw3-dev libvulkan-dev \
29+
libvulkan-dev \
3030
glslang-tools glslang-dev libglm-dev \
3131
pkg-config \
32+
libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev \
3233
libavcodec-dev libavformat-dev libavutil-dev libswscale-dev patchelf
34+
- name: Build and install GLFW 3.4 (Linux X11 platform hints required)
35+
run: |
36+
git clone --depth 1 --branch 3.4 https://github.com/glfw/glfw.git /tmp/glfw
37+
# Build X11-only to avoid Wayland issue
38+
# See issue #68: https://github.com/jamylak/vsdf/issues/68
39+
cmake -S /tmp/glfw -B /tmp/glfw/build -G Ninja \
40+
-DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF \
41+
-DGLFW_BUILD_DOCS=OFF -DGLFW_INSTALL=ON \
42+
-DGLFW_BUILD_WAYLAND=OFF
43+
cmake --build /tmp/glfw/build
44+
sudo cmake --install /tmp/glfw/build
3345
3446
- name: Configure
3547
run: cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wno-error=array-bounds" -G Ninja .
@@ -116,7 +128,7 @@ jobs:
116128
runs-on: ubuntu-latest
117129
timeout-minutes: 5
118130
env:
119-
VK_ICD_FILENAMES: /usr/share/vulkan/icd.d/lvp_icd.x86_64.json
131+
VK_ICD_FILENAMES: /usr/share/vulkan/icd.d/lvp_icd.json
120132

121133
steps:
122134
- name: Download artifact

default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
}:
1717

1818
let
19+
_ = assert lib.versionAtLeast glfw.version "3.4"; null;
1920
volk = fetchFromGitHub {
2021
owner = "zeux";
2122
repo = "volk";

flake.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
};
3232
in
3333
{
34-
devShells.default = pkgs.mkShell rec {
34+
devShells.default =
35+
assert pkgs.lib.versionAtLeast pkgs.glfw.version "3.4";
36+
pkgs.mkShell rec {
3537
name = "vsdf";
3638

3739
packages = with pkgs; [

include/glfwutils.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#define GLFW_INCLUDE_NONE
55
#include <GLFW/glfw3.h>
6+
#include <cctype>
7+
#include <cstdlib>
68
#include <stdexcept>
79
#include <string>
810

@@ -18,6 +20,41 @@ namespace glfwutils {
1820
* Must be called once before creating windows.
1921
*/
2022
static void initGLFW() {
23+
#if defined(__linux__)
24+
#if (GLFW_VERSION_MAJOR < 3) || \
25+
(GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR < 4)
26+
#error "GLFW 3.4+ is required on Linux to force X11 via GLFW_PLATFORM. See issue #68: https://github.com/jamylak/vsdf/issues/68"
27+
#endif
28+
const char *platformEnv = std::getenv("GLFW_PLATFORM");
29+
if (platformEnv && platformEnv[0] != '\0') {
30+
std::string platform = platformEnv;
31+
for (char &ch : platform) {
32+
ch = static_cast<char>(
33+
std::tolower(static_cast<unsigned char>(ch)));
34+
}
35+
int platformHint = 0;
36+
if (platform == "x11") {
37+
platformHint = GLFW_PLATFORM_X11;
38+
} else if (platform == "wayland") {
39+
platformHint = GLFW_PLATFORM_WAYLAND;
40+
} else if (platform == "null") {
41+
platformHint = GLFW_PLATFORM_NULL;
42+
} else {
43+
throw std::runtime_error(
44+
"Invalid GLFW_PLATFORM value on Linux: " + platform +
45+
" (expected x11, wayland, null)");
46+
}
47+
glfwInitHint(GLFW_PLATFORM, platformHint);
48+
} else {
49+
// Default to X11 on Linux to avoid Wayland/libdecor ASAN leak.
50+
// See issue #68: https://github.com/jamylak/vsdf/issues/68
51+
// Summary: ASAN reports leaks seemingly from the Wayland decoration stack
52+
// (libdecor/GTK/Pango/Fontconfig via GLFW) that persist until process exit.
53+
// This is not related to render/present stalls; override with GLFW_PLATFORM
54+
// if you explicitly want Wayland.
55+
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
56+
}
57+
#endif
2158
if (!glfwInit()) {
2259
throw std::runtime_error("Failed to initialize GLFW");
2360
}

linux-tests.Dockerfile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,33 @@ RUN apt-get update && \
1010
cmake \
1111
ninja-build \
1212
make \
13+
git \
14+
ca-certificates \
1315
libgtest-dev \
1416
libspdlog-dev \
15-
libglfw3 libglfw3-dev \
1617
libvulkan-dev \
1718
glslang-tools \
1819
glslang-dev \
1920
libglm-dev \
2021
pkg-config \
22+
libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev \
2123
libavcodec-dev \
2224
libavformat-dev \
2325
libavutil-dev \
2426
libswscale-dev
2527
# && rm -rf /var/lib/apt/lists/*
2628

29+
# GLFW 3.4+ is required for GLFW_PLATFORM hints on Linux.
30+
# Build X11-only to avoid Wayland issue
31+
# See issue #68: https://github.com/jamylak/vsdf/issues/68
32+
RUN git clone --depth 1 --branch 3.4 https://github.com/glfw/glfw.git /tmp/glfw && \
33+
cmake -S /tmp/glfw -B /tmp/glfw/build -G Ninja \
34+
-DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF \
35+
-DGLFW_BUILD_DOCS=OFF -DGLFW_INSTALL=ON \
36+
-DGLFW_BUILD_WAYLAND=OFF && \
37+
cmake --build /tmp/glfw/build && \
38+
cmake --install /tmp/glfw/build
39+
2740
COPY . /app
2841

2942
RUN mkdir -p build && \

0 commit comments

Comments
 (0)