Hello, NixOS newbie here, loving it so far.
I discovered this weird thing. When adding -fsanitize=address
to a build of a simple SDL + OpenGL C++ program, I get the following error from SDL when attempting to create the window:
Couldn't find matching GLX visual
If I remove -fsanitize=address
from CXXFLAGS, it works perfectly.
This is happening on NixOS stable 23.05, inside nix-shell -p SDL2
. Please let me know if I should provide any other details about the setup, or more detailed repro steps.
Any ideas? Should I link asan differently here?
I’m using examples/example_sdl2_opengl3 from GitHub - ocornut/imgui: Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies, with these two changes: add -fsanitize=address
to CXXFLAGS in the Makefile, and log SDL_GetError()
right after creating the window.
Thanks in advance,
fd
diff --git a/examples/example_sdl2_opengl3/Makefile b/examples/example_sdl2_opengl3/Makefile
index 5b4f9419..9189edf8 100644
--- a/examples/example_sdl2_opengl3/Makefile
+++ b/examples/example_sdl2_opengl3/Makefile
@@ -24,7 +24,7 @@ UNAME_S := $(shell uname -s)
LINUX_GL_LIBS = -lGL
CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
-CXXFLAGS += -g -Wall -Wformat
+CXXFLAGS += -g -Wall -Wformat -fsanitize=address
LIBS =
##---------------------------------------------------------------------
diff --git a/examples/example_sdl2_opengl3/main.cpp b/examples/example_sdl2_opengl3/main.cpp
index 344f7452..f5ddf709 100644
--- a/examples/example_sdl2_opengl3/main.cpp
+++ b/examples/example_sdl2_opengl3/main.cpp
@@ -68,6 +68,7 @@ int main(int, char**)
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
+ printf("window: %p, error: %s\n", window, SDL_GetError());
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync