From 08352dd997f729c276f6726f57b2d488a5ea51bd Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Wed, 4 Mar 2026 21:31:01 +0100 Subject: [PATCH] don't pass a reference to a temporary to physics_thread --- include/threaded_physics.hpp | 37 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/include/threaded_physics.hpp b/include/threaded_physics.hpp index c1a03d7..4bbb2a8 100644 --- a/include/threaded_physics.hpp +++ b/include/threaded_physics.hpp @@ -15,7 +15,8 @@ class threaded_physics { - struct add_mass {}; + struct add_mass + {}; struct add_spring { @@ -23,24 +24,25 @@ class threaded_physics size_t b; }; - struct clear_graph {}; + struct clear_graph + {}; using command = std::variant; struct physics_state { - #ifdef TRACY +#ifdef TRACY TracyLockable(std::mutex, command_mtx); - #else +#else std::mutex command_mtx; - #endif +#endif std::queue pending_commands; - #ifdef TRACY +#ifdef TRACY TracyLockable(std::mutex, data_mtx); - #else +#else std::mutex data_mtx; - #endif +#endif std::condition_variable_any data_ready_cnd; std::condition_variable_any data_consumed_cnd; Vector3 mass_center = Vector3Zero(); @@ -55,14 +57,17 @@ class threaded_physics }; private: + std::optional* const> thread_pool; std::thread physics; public: physics_state state; public: - explicit threaded_physics(const std::optional* const> thread_pool = std::nullopt) - : physics(physics_thread, std::ref(state), std::ref(thread_pool)) {} + explicit threaded_physics( + const std::optional* const> _thread_pool = std::nullopt) + : thread_pool(_thread_pool), physics(physics_thread, std::ref(state), std::ref(thread_pool)) + {} threaded_physics(const threaded_physics& copy) = delete; auto operator=(const threaded_physics& copy) -> threaded_physics& = delete; @@ -78,17 +83,19 @@ public: } private: - #ifdef ASYNC_OCTREE +#ifdef ASYNC_OCTREE static auto set_octree_pool_thread_name(size_t idx) -> void; - #endif +#endif - static auto physics_thread(physics_state& state, std::optional* const> thread_pool) -> void; + static auto physics_thread(physics_state& state, + std::optional* const> thread_pool) -> void; public: auto clear_cmd() -> void; auto add_mass_cmd() -> void; auto add_spring_cmd(size_t a, size_t b) -> void; - auto add_mass_springs_cmd(size_t num_masses, const std::vector>& springs) -> void; + auto add_mass_springs_cmd(size_t num_masses, + const std::vector>& springs) -> void; }; -#endif \ No newline at end of file +#endif