diff --git a/panda/src/sgmanip/config_sgmanip.cxx b/panda/src/sgmanip/config_sgmanip.cxx index 966a11fff7..d632442b41 100644 --- a/panda/src/sgmanip/config_sgmanip.cxx +++ b/panda/src/sgmanip/config_sgmanip.cxx @@ -26,6 +26,13 @@ Configure(config_sgmanip); NotifyCategoryDef(sgmanip, ""); +// Set this to true to generate an assertion failure whenever you +// first attempt to apply a singular transform matrix to the scene +// graph, or false to ignore this. The default is true, which makes +// it much easier to track down singular matrix errors. In NDEBUG +// mode, this is ignored and is effectively always false. +const bool check_singular_transform = config_sgmanip.GetBool("check-singular-transform", true); + ConfigureFn(config_sgmanip) { NodePath::init_type(); PosLerpFunctor::init_type(); diff --git a/panda/src/sgmanip/config_sgmanip.h b/panda/src/sgmanip/config_sgmanip.h index ce3cdc724c..ee5c79c305 100644 --- a/panda/src/sgmanip/config_sgmanip.h +++ b/panda/src/sgmanip/config_sgmanip.h @@ -25,4 +25,7 @@ NotifyCategoryDecl(sgmanip, EXPCL_PANDA, EXPTP_PANDA); +// Configure variables for sgmanip package. +extern const bool EXPCL_PANDA check_singular_transform; + #endif diff --git a/panda/src/sgmanip/nodePath.cxx b/panda/src/sgmanip/nodePath.cxx index 94ee789241..0110fdfc8f 100644 --- a/panda/src/sgmanip/nodePath.cxx +++ b/panda/src/sgmanip/nodePath.cxx @@ -1410,7 +1410,19 @@ set_mat(const LMatrix4f &mat) { << "Setting transform on data graph arc.\n" << "(This is probably meaningless. Did you mean to do this to the bottom node?)\n"; } -#endif +#endif // NDEBUG + +#ifndef NDEBUG + if (check_singular_transform) { + LMatrix4f inv_mat; + bool ok = inv_mat.invert_from(mat); + if (!ok) { + sgmanip_cat.error() + << "Attempt to set a singular transform on " << *this << "\n"; + nassertv(false); + } + } +#endif // NDEBUG arc()->set_transition(new TransformTransition(mat)); } @@ -1859,6 +1871,18 @@ set_mat(const NodePath &other, const LMatrix4f &mat) { new_mat_ptr = &new_mat; } +#ifndef NDEBUG + if (check_singular_transform) { + LMatrix4f inv_mat; + bool ok = inv_mat.invert_from(*new_mat_ptr); + if (!ok) { + sgmanip_cat.error() + << "Attempt to set a singular transform on " << *this << "\n"; + nassertv(false); + } + } +#endif // NDEBUG + darc->set_transition(new TransformTransition(*new_mat_ptr)); }