From 25c93c09c762a64ad28e580c6490b6d90d757aa2 Mon Sep 17 00:00:00 2001 From: Michal Pelka Date: Fri, 9 Oct 2026 21:08:33 +0200 Subject: [PATCH] Remove step 1 cache after saving the session in command-line mode The cache directory was only removed by the GUI's on_exit, so headless runs ( and ) left all cached chunk points on disk. Extract remove_cache() and call it after the session is saved; on_exit uses the same helper. Fixes #489 Co-Authored-By: Claude Opus 5.5 --- ...andeye_data_and_drop_here-precision_forestry.cpp | 5 +---- apps/lidar_odometry_step_1/lidar_odometry.cpp | 13 +++++++++++++ apps/lidar_odometry_step_1/lidar_odometry.h | 2 ++ apps/lidar_odometry_step_1/lidar_odometry_gui.cpp | 7 +++---- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/lidar_odometry_step_1/drag_folder_with_mandeye_data_and_drop_here-precision_forestry.cpp b/apps/lidar_odometry_step_1/drag_folder_with_mandeye_data_and_drop_here-precision_forestry.cpp index e8535b88..f40a1bdd 100644 --- a/apps/lidar_odometry_step_1/drag_folder_with_mandeye_data_and_drop_here-precision_forestry.cpp +++ b/apps/lidar_odometry_step_1/drag_folder_with_mandeye_data_and_drop_here-precision_forestry.cpp @@ -2217,10 +2217,7 @@ void display() void on_exit() { - // remove cache - std::cout << "remove cache: '" << params.working_directory_cache << "' START" << std::endl; - std::filesystem::remove_all(params.working_directory_cache); - std::cout << "remove cache: '" << params.working_directory_cache << "' FINISHED" << std::endl; + remove_cache(params); } void mouse(int glut_button, int state, int x, int y) diff --git a/apps/lidar_odometry_step_1/lidar_odometry.cpp b/apps/lidar_odometry_step_1/lidar_odometry.cpp index 5dea711c..d02e0d52 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry.cpp +++ b/apps/lidar_odometry_step_1/lidar_odometry.cpp @@ -1192,6 +1192,19 @@ void release_raw_clouds(std::vector>& pointsPerFile, Lidar release_freed_heap(); } +void remove_cache(const LidarOdometryParams& params) +{ + if (params.working_directory_cache.empty()) + return; + std::cout << "remove cache: '" << params.working_directory_cache << "' START" << std::endl; + std::error_code ec; + fs::remove_all(params.working_directory_cache, ec); + if (ec) + std::cerr << "remove cache: '" << params.working_directory_cache << "' FAILED: " << ec.message() << std::endl; + else + std::cout << "remove cache: '" << params.working_directory_cache << "' FINISHED" << std::endl; +} + std::vector run_lidar_odometry(const std::string& input_dir, LidarOdometryParams& params) { HDMAP_ZONE_SCOPE("run_lidar_odometry"); diff --git a/apps/lidar_odometry_step_1/lidar_odometry.h b/apps/lidar_odometry_step_1/lidar_odometry.h index 41d9cb5e..3b2fc1da 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry.h +++ b/apps/lidar_odometry_step_1/lidar_odometry.h @@ -31,6 +31,8 @@ bool compute_step_1( const std::atomic& pause); // after a successful step 1: free the raw clouds (and the lazy loader) — nothing after step 1 reads them void release_raw_clouds(std::vector>& pointsPerFile, LidarOdometryParams& params); +// remove params.working_directory_cache; call only once nothing reads worker_data[*].*_cache_file_name any more +void remove_cache(const LidarOdometryParams& params); void run_consistency(std::vector& worker_data, const LidarOdometryParams& params); void filter_reference_buckets(LidarOdometryParams& params); void load_reference_point_clouds(const std::vector& input_file_names, LidarOdometryParams& params); diff --git a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp index c528603c..03099c22 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp +++ b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp @@ -2626,10 +2626,7 @@ void display() void on_exit() { - // remove cache - std::cout << "remove cache: '" << params.working_directory_cache << "' START" << std::endl; - std::filesystem::remove_all(params.working_directory_cache); - std::cout << "remove cache: '" << params.working_directory_cache << "' FINISHED" << std::endl; + remove_cache(params); } void mouse(int glut_button, int state, int x, int y) @@ -2759,6 +2756,7 @@ int main(int argc, char* argv[]) const fs::path result_dir = get_next_result_path(working_directory); save_results(false, elapsed_seconds.count(), working_directory, worker_data, params, result_dir); std::cout << "Results saved to folder: '" << result_dir.string() << "'" << std::endl; + remove_cache(params); } } else if (argc == 4) // runnning from command line with custom params @@ -2789,6 +2787,7 @@ int main(int argc, char* argv[]) << "Elapsed time: " << formatTime(elapsed_seconds.count()).c_str() << "s\n"; save_results(false, elapsed_seconds.count(), working_directory, worker_data, params, argv[3]); + remove_cache(params); } else // full GUI mode {