From 9d4ba6acb987f870f930c16fceec76b4d66c41d5 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Fri, 4 Nov 2011 16:56:19 +0000 Subject: [PATCH] Throw exception rather than assert (which crashes MATLAB) --- gtsam/inference/Factor-inl.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gtsam/inference/Factor-inl.h b/gtsam/inference/Factor-inl.h index 822c6a0cd..6b911e0c1 100644 --- a/gtsam/inference/Factor-inl.h +++ b/gtsam/inference/Factor-inl.h @@ -44,9 +44,12 @@ namespace gtsam { void Factor::assertInvariants() const { #ifndef NDEBUG // Check that keys are all unique - std::multiset nonunique(keys_.begin(), keys_.end()); - std::set unique(keys_.begin(), keys_.end()); - assert(nonunique.size() == unique.size() && std::equal(nonunique.begin(), nonunique.end(), unique.begin())); + std::multiset < Key > nonunique(keys_.begin(), keys_.end()); + std::set < Key > unique(keys_.begin(), keys_.end()); + bool correct = (nonunique.size() != unique.size()) + && std::equal(nonunique.begin(), nonunique.end(), unique.begin()); + if (!correct) + throw std::logic_error("Factor::assertInvariants: detected inconsistency"); #endif }