From 1c754738bd44be0410f1451266c1bb548dcd7cf1 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 13:00:08 +0100 Subject: [PATCH] physics: Prevent adding same Physical to more than one PhysicalNode Also silently ignore if the same Physical is added to the same PhysicalNode more than once. --- panda/src/physics/physicalNode.I | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/panda/src/physics/physicalNode.I b/panda/src/physics/physicalNode.I index 407cf52f5a..0808fd51a2 100644 --- a/panda/src/physics/physicalNode.I +++ b/panda/src/physics/physicalNode.I @@ -42,10 +42,14 @@ get_num_physicals() const { } /** - + * Adds a Physical to this PhysicalNode. If it is already added to this node, + * does nothing. It is an error to add a Physical to multiple PhysicalNodes. */ INLINE void PhysicalNode:: add_physical(Physical *physical) { - _physicals.push_back(physical); - physical->_physical_node = this; + if (physical->_physical_node != this) { + nassertv(physical->_physical_node == nullptr); + _physicals.push_back(physical); + physical->_physical_node = this; + } }