diff options
author | Marius Kintel <marius@kintel.net> | 2014-01-06 06:27:01 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2014-01-06 06:27:01 (GMT) |
commit | 5fc6af77828e671d19bcc790da7c899633e6a3e4 (patch) | |
tree | ddbe14303cbabf6b4a987b9a032846af55024f67 | |
parent | 28fb4dc4cb775c2feb2640b2ef74bc3d9fc3114d (diff) |
In some rare cases, subtrees got invalidated and caused an assert failure
-rw-r--r-- | src/csgtermnormalizer.cc | 24 | ||||
-rw-r--r-- | src/csgtermnormalizer.h | 1 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/csgtermnormalizer.cc b/src/csgtermnormalizer.cc index 461e965..2f79841 100644 --- a/src/csgtermnormalizer.cc +++ b/src/csgtermnormalizer.cc @@ -32,6 +32,22 @@ shared_ptr<CSGTerm> CSGTermNormalizer::normalize(const shared_ptr<CSGTerm> &root return temp; } +/*! + After aborting, a subtree might have become invalidated (NULL child term) + since terms can be instantiated multiple times. + This will search for NULL children an recursively repair the corresponding + subtree. + */ +shared_ptr<CSGTerm> CSGTermNormalizer::cleanup_term(shared_ptr<CSGTerm> &t) +{ + if (t->type != CSGTerm::TYPE_PRIMITIVE) { + if (t->left) t->left = cleanup_term(t->left); + if (t->right) t->right = cleanup_term(t->right); + return collapse_null_terms(t); + } + else return t; +} + shared_ptr<CSGTerm> CSGTermNormalizer::normalizePass(shared_ptr<CSGTerm> term) { // This function implements the CSG normalization @@ -62,7 +78,13 @@ shared_ptr<CSGTerm> CSGTermNormalizer::normalizePass(shared_ptr<CSGTerm> term) if (!this->aborted) term->right = normalizePass(term->right); // FIXME: Do we need to take into account any transformation of item here? - return collapse_null_terms(term); + shared_ptr<CSGTerm> t = collapse_null_terms(term); + + if (this->aborted) { + if (t) t = cleanup_term(t); + } + + return t; } shared_ptr<CSGTerm> CSGTermNormalizer::collapse_null_terms(const shared_ptr<CSGTerm> &term) diff --git a/src/csgtermnormalizer.h b/src/csgtermnormalizer.h index f7a444f..bb55141 100644 --- a/src/csgtermnormalizer.h +++ b/src/csgtermnormalizer.h @@ -15,6 +15,7 @@ private: shared_ptr<CSGTerm> normalizePass(shared_ptr<CSGTerm> term) ; bool match_and_replace(shared_ptr<CSGTerm> &term); shared_ptr<CSGTerm> collapse_null_terms(const shared_ptr<CSGTerm> &term); + shared_ptr<CSGTerm> cleanup_term(shared_ptr<CSGTerm> &t); unsigned int count(const shared_ptr<CSGTerm> &term) const; bool aborted; |