浏览代码

better message for singular invert assertion

David Rose 21 年之前
父节点
当前提交
67b9dc9367
共有 3 个文件被更改,包括 21 次插入15 次删除
  1. 7 6
      panda/src/linmath/lmatrix3_src.I
  2. 8 8
      panda/src/linmath/lmatrix4_src.I
  3. 6 1
      panda/src/linmath/lquaternion_src.I

+ 7 - 6
panda/src/linmath/lmatrix3_src.I

@@ -605,9 +605,7 @@ multiply(const FLOATNAME(LMatrix3) &other1, const FLOATNAME(LMatrix3) &other2) {
 // faster than operator * since it writes result in place, avoiding extra copying
 // this will fail if you try to mat.multiply(mat,other_mat)
 
-  #ifdef _DEBUG
-     assert((&other1 != this) && (&other2 != this));
-  #endif
+  nassertv((&other1 != this) && (&other2 != this));
 
   MATRIX3_PRODUCT((*this),other1,other2);
 }
@@ -981,9 +979,7 @@ rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis,
 
   // Normalize the axis.
   FLOATTYPE length_sq = axis_0 * axis_0 + axis_1 * axis_1 + axis_2 * axis_2;
-#ifdef _DEBUG
   nassertr(length_sq != 0.0f, ident_mat());
-#endif
   FLOATTYPE recip_length = 1.0f/csqrt(length_sq);
 
   axis_0 *= recip_length;
@@ -1207,6 +1203,11 @@ INLINE_LINMATH FLOATNAME(LMatrix3)
 invert(const FLOATNAME(LMatrix3) &a) {
   FLOATNAME(LMatrix3) result;
   bool nonsingular = result.invert_from(a);
-  nassertr(nonsingular, FLOATNAME(LMatrix3)::ident_mat());
+#ifndef NDEBUG
+  if (!nonsingular) {
+    nassert_raise("Attempt to compute inverse of singular matrix!");
+    return FLOATNAME(LMatrix3)::ident_mat();
+  }
+#endif
   return result;
 }

+ 8 - 8
panda/src/linmath/lmatrix4_src.I

@@ -785,10 +785,7 @@ multiply(const FLOATNAME(LMatrix4) &other1, const FLOATNAME(LMatrix4) &other2) {
 // faster than operator * since it writes result in place, avoiding extra copying
 // this will fail if you try to mat.multiply(mat,other_mat)
 
-  #ifdef _DEBUG
-     assert((&other1 != this) && (&other2 != this));
-  #endif
-
+  nassertv((&other1 != this) && (&other2 != this));
   MATRIX4_PRODUCT((*this),other1,other2);
 }
 
@@ -1227,9 +1224,7 @@ rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis,
 */
 
           FLOATTYPE length_sq = axis_0 * axis_0 + axis_1 * axis_1 + axis_2 * axis_2;
-          #ifdef _DEBUG
-              nassertr(length_sq != 0.0f, ident_mat());
-          #endif
+          nassertr(length_sq != 0.0f, ident_mat());
           FLOATTYPE recip_length = 1.0f/csqrt(length_sq);
 
           axis_0 *= recip_length;
@@ -1504,7 +1499,12 @@ INLINE_LINMATH FLOATNAME(LMatrix4)
 invert(const FLOATNAME(LMatrix4) &a) {
   FLOATNAME(LMatrix4) result;
   bool nonsingular = result.invert_from(a);
-  nassertr(nonsingular, FLOATNAME(LMatrix4)::ident_mat());
+#ifndef NDEBUG
+  if (!nonsingular) {
+    nassert_raise("Attempt to compute inverse of singular matrix!");
+    return FLOATNAME(LMatrix4)::ident_mat();
+  }
+#endif
   return result;
 }
 

+ 6 - 1
panda/src/linmath/lquaternion_src.I

@@ -410,7 +410,12 @@ INLINE_LINMATH FLOATNAME(LQuaternion)
 invert(const FLOATNAME(LQuaternion) &a) {
   FLOATNAME(LQuaternion) result;
   bool nonsingular = result.invert_from(a);
-  nassertr(nonsingular, FLOATNAME(LQuaternion)::ident_quat());
+#ifndef NDEBUG
+  if (!nonsingular) {
+    nassert_raise("Attempt to compute inverse of singular quaternion!");
+    return FLOATNAME(LQuaternion)::ident_quat();
+  }
+#endif
   return result;
 }