Selaa lähdekoodia

fix self-deadlock issues when showing collision solids

David Rose 18 vuotta sitten
vanhempi
sitoutus
515d96ab17

+ 26 - 3
panda/src/collide/collisionSolid.I

@@ -50,7 +50,7 @@ set_tangible(bool tangible) {
 INLINE bool CollisionSolid::
 is_tangible() const {
   MutexHolder holder(_lock);
-  return (_flags & F_tangible) != 0;
+  return do_is_tangible();
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -93,7 +93,7 @@ clear_effective_normal() {
 INLINE bool CollisionSolid::
 has_effective_normal() const {
   MutexHolder holder(_lock);
-  return respect_effective_normal && (_flags & F_effective_normal) != 0;
+  return do_has_effective_normal();
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -105,8 +105,8 @@ has_effective_normal() const {
 ////////////////////////////////////////////////////////////////////
 INLINE const LVector3f &CollisionSolid::
 get_effective_normal() const {
-  nassertr(has_effective_normal(), LVector3f::zero());
   MutexHolder holder(_lock);
+  nassertr(do_has_effective_normal(), LVector3f::zero());
   return _effective_normal;
 }
 
@@ -143,6 +143,29 @@ get_respect_effective_normal() const {
   return (_flags & F_ignore_effective_normal) == 0;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionSolid::do_is_tangible
+//       Access: Protected
+//  Description: Returns whether the solid is considered 'tangible' or
+//               not. Assumes the lock is already held.
+////////////////////////////////////////////////////////////////////
+INLINE bool CollisionSolid::
+do_is_tangible() const {
+  return (_flags & F_tangible) != 0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionSolid::do_has_effective_normal
+//       Access: Protected
+//  Description: Returns true if a special normal was set by
+//               set_effective_normal(), false otherwise.  Assumes the
+//               lock is already held.
+////////////////////////////////////////////////////////////////////
+INLINE bool CollisionSolid::
+do_has_effective_normal() const {
+  return respect_effective_normal && (_flags & F_effective_normal) != 0;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionSolid::mark_internal_bounds_stale
 //       Access: Protected

+ 18 - 6
panda/src/collide/collisionSolid.cxx

@@ -412,6 +412,8 @@ fill_viz_geom() {
 //               visualizations in solid.  This automatically returns
 //               the appropriate state according to the setting of
 //               _tangible.
+//
+//               Assumes the lock is already held.
 ////////////////////////////////////////////////////////////////////
 CPT(RenderState) CollisionSolid::
 get_solid_viz_state() {
@@ -425,7 +427,7 @@ get_solid_viz_state() {
        TransparencyAttrib::make(TransparencyAttrib::M_alpha));
   }
 
-  if (!is_tangible()) {
+  if (!do_is_tangible()) {
     static CPT(RenderState) intangible_state = (const RenderState *)NULL;
     if (intangible_state == (const RenderState *)NULL) {
       intangible_state = base_state->add_attrib
@@ -433,7 +435,7 @@ get_solid_viz_state() {
     }
     return intangible_state;
 
-  } else if (has_effective_normal()) {
+  } else if (do_has_effective_normal()) {
     static CPT(RenderState) fakenormal_state = (const RenderState *)NULL;
     if (fakenormal_state == (const RenderState *)NULL) {
       fakenormal_state = base_state->add_attrib
@@ -459,6 +461,8 @@ get_solid_viz_state() {
 //               visualizations in wireframe.  This automatically returns
 //               the appropriate state according to the setting of
 //               _tangible.
+//
+//               Assumes the lock is already held.
 ////////////////////////////////////////////////////////////////////
 CPT(RenderState) CollisionSolid::
 get_wireframe_viz_state() {
@@ -472,7 +476,7 @@ get_wireframe_viz_state() {
        TransparencyAttrib::make(TransparencyAttrib::M_none));
   }
 
-  if (!is_tangible()) {
+  if (!do_is_tangible()) {
     static CPT(RenderState) intangible_state = (const RenderState *)NULL;
     if (intangible_state == (const RenderState *)NULL) {
       intangible_state = base_state->add_attrib
@@ -480,7 +484,7 @@ get_wireframe_viz_state() {
     }
     return intangible_state;
 
-  } else if (has_effective_normal()) {
+  } else if (do_has_effective_normal()) {
     static CPT(RenderState) fakenormal_state = (const RenderState *)NULL;
     if (fakenormal_state == (const RenderState *)NULL) {
       fakenormal_state = base_state->add_attrib
@@ -505,6 +509,8 @@ get_wireframe_viz_state() {
 //  Description: Returns a RenderState for rendering collision
 //               visualizations for things that are neither solid nor
 //               exactly wireframe, like rays and segments.
+//
+//               Assumes the lock is already held.
 ////////////////////////////////////////////////////////////////////
 CPT(RenderState) CollisionSolid::
 get_other_viz_state() {
@@ -530,6 +536,8 @@ get_other_viz_state() {
 //               visualizations in solid.  This automatically returns
 //               the appropriate state according to the setting of
 //               _tangible.
+//
+//               Assumes the lock is already held.
 ////////////////////////////////////////////////////////////////////
 CPT(RenderState) CollisionSolid::
 get_solid_bounds_viz_state() {
@@ -543,7 +551,7 @@ get_solid_bounds_viz_state() {
        TransparencyAttrib::make(TransparencyAttrib::M_alpha));
   }
 
-  if (!is_tangible()) {
+  if (!do_is_tangible()) {
     static CPT(RenderState) intangible_state = (const RenderState *)NULL;
     if (intangible_state == (const RenderState *)NULL) {
       intangible_state = base_state->add_attrib
@@ -551,7 +559,7 @@ get_solid_bounds_viz_state() {
     }
     return intangible_state;
 
-  } else if (has_effective_normal()) {
+  } else if (do_has_effective_normal()) {
     static CPT(RenderState) fakenormal_state = (const RenderState *)NULL;
     if (fakenormal_state == (const RenderState *)NULL) {
       fakenormal_state = base_state->add_attrib
@@ -577,6 +585,8 @@ get_solid_bounds_viz_state() {
 //               visualizations in wireframe.  This automatically returns
 //               the appropriate state according to the setting of
 //               _tangible.
+//
+//               Assumes the lock is already held.
 ////////////////////////////////////////////////////////////////////
 CPT(RenderState) CollisionSolid::
 get_wireframe_bounds_viz_state() {
@@ -601,6 +611,8 @@ get_wireframe_bounds_viz_state() {
 //  Description: Returns a RenderState for rendering collision
 //               visualizations for things that are neither solid nor
 //               exactly wireframe, like rays and segments.
+//
+//               Assumes the lock is already held.
 ////////////////////////////////////////////////////////////////////
 CPT(RenderState) CollisionSolid::
 get_other_bounds_viz_state() {

+ 3 - 0
panda/src/collide/collisionSolid.h

@@ -95,6 +95,9 @@ PUBLISHED:
   virtual void write(ostream &out, int indent_level = 0) const;
 
 protected:
+  INLINE bool do_is_tangible() const;
+  INLINE bool do_has_effective_normal() const;
+
   INLINE void mark_internal_bounds_stale();
   virtual PT(BoundingVolume) compute_internal_bounds() const;