From 58235ac52ec719fee8413a212a20a23e006a75a2 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Wed, 25 Feb 2026 13:23:01 +0100 Subject: [PATCH] some valgrind bullshit --- .gitignore | 1 + CMakeLists.txt | 4 +-- compile_commands.json | 2 +- flake.nix | 1 + src/main.cpp | 6 ++-- src/state.cpp | 4 +++ valgrind.supp | 66 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 valgrind.supp diff --git a/.gitignore b/.gitignore index 6ace9b9..dbb1bac 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ cmake-build-release /platform /result /.gdb_history +/valgrind.log diff --git a/CMakeLists.txt b/CMakeLists.txt index 60df08b..4725ac7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,12 +20,12 @@ if(USE_TRACY) option(TRACY_ENABLE "" ON) option(TRACY_ON_DEMAND "" ON) - # Enable tracy macros in the application + # Enable tracy macros in the application. Uses a LOT of memory. add_compile_definitions(TRACY) endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wno-unused-parameter -Wunreachable-code") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -ggdb -fsanitize=undefined") # -fsanitize=address already fails on InitWindow() +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O3 -ggdb -fsanitize=undefined") # -fsanitize=address already fails on InitWindow() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native") message("-- CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") diff --git a/compile_commands.json b/compile_commands.json index 66636ac..fd9db9d 120000 --- a/compile_commands.json +++ b/compile_commands.json @@ -1 +1 @@ -./cmake-build-debug/compile_commands.json \ No newline at end of file +./cmake-build-release/compile_commands.json \ No newline at end of file diff --git a/flake.nix b/flake.nix index ddcf235..e6101d7 100644 --- a/flake.nix +++ b/flake.nix @@ -287,6 +287,7 @@ rec { abbr -a release "${buildRelease} && ./cmake-build-release/masssprings" abbr -a rungdb "${buildDebug} && gdb --tui ./cmake-build-debug/masssprings" abbr -a runtracy "tracy -a 127.0.0.1 &; ${buildRelease} && sudo -E ./cmake-build-release/masssprings" + abbr -a runvalgrind "${buildDebug} && valgrind --leak-check=full --show-reachable=no --show-leak-kinds=definite,indirect,possible --track-origins=no --suppressions=valgrind.supp --log-file=valgrind.log ./cmake-build-debug/masssprings && cat valgrind.log" ''; in builtins.concatStringsSep "\n" [ diff --git a/src/main.cpp b/src/main.cpp index e7ca7da..87f84e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,9 +13,9 @@ #include #endif -// TODO: Graph interaction -// - Click states to display them in the board -// TODO: Add a move history and backspace to go back +// TODO: Click states to display them in the board + +// NOTE: Tracy uses a huge amount of memory. For longer testing disable Tracy. auto main(int argc, char *argv[]) -> int { std::string preset_file; diff --git a/src/state.cpp b/src/state.cpp index 02b502e..1d6f115 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -86,7 +86,9 @@ auto StateManager::NextPath() -> void { } auto StateManager::FillGraph() -> void { +#ifdef TRACY ZoneScoped; +#endif ClearGraph(); @@ -178,7 +180,9 @@ auto StateManager::FindWinningStates() -> void { } auto StateManager::FindTargetDistances() -> void { +#ifdef TRACY ZoneScoped; +#endif if (springs.size() == 0 || winning_states.size() == 0) { return; diff --git a/valgrind.supp b/valgrind.supp new file mode 100644 index 0000000..2f51be6 --- /dev/null +++ b/valgrind.supp @@ -0,0 +1,66 @@ +{ + glib_malloc + Memcheck:Leak + ... + obj:*/libglib-2.0.so* +} +{ + gtk_leaks + Memcheck:Leak + ... + obj:*/libgtk-3.so* +} +{ + mesa_leaks + Memcheck:Leak + ... + obj:*/libGLX* +} +{ + glfw_leaks + Memcheck:Leak + ... + obj:*/libglfw.so* +} +{ + wayland_leaks + Memcheck:Leak + ... + obj:*/libwayland*.so* +} +{ + dbus_leaks + Memcheck:Leak + ... + obj:*/libdbus*.so* +} +{ + egl_leaks + Memcheck:Leak + ... + obj:*/libEGL*.so* +} +{ + x11_leaks + Memcheck:Leak + ... + obj:*/libX11* +} +{ + fontconfig_leaks + Memcheck:Leak + ... + obj:*/libfontconfig.so* +} +{ + pango_leaks + Memcheck:Leak + ... + obj:*/libpango*.so* +} +{ + nvidia_leaks + Memcheck:Leak + ... + obj:*/libnvidia*.so* +}