From d388f35fd0dabb4d7af3243294fc614792709838 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 21 Dec 2011 17:07:41 +0000 Subject: [PATCH] 0000525: Crash when doing an undo of an already deleted object git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5334 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/App/Document.cpp | 14 +++++--------- src/App/Document.h | 2 +- src/Mod/Test/Document.py | 9 +++++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 457bc81439..9c9399ccb0 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -294,19 +294,20 @@ void Document::openTransaction(const char* name) d->activeUndoTransaction = new Transaction(); if (name) d->activeUndoTransaction->Name = name; + else + d->activeUndoTransaction->Name = ""; } } void Document::_checkTransaction(void) { // if the undo is active but no transaction open, open one! - if (d->iUndoMode) - if (! d->activeUndoTransaction) + if (d->iUndoMode) { + if (!d->activeUndoTransaction) openTransaction(); - + } } - void Document::_clearRedos() { while (!mRedoTransactions.empty()) { @@ -420,7 +421,6 @@ void Document::onChanged(const Property* prop) void Document::onBeforeChangeProperty(const DocumentObject *Who, const Property *What) { - _checkTransaction(); if (d->activeUndoTransaction && !d->rollback) d->activeUndoTransaction->addObjectChange(Who,What); } @@ -1232,8 +1232,6 @@ bool Document::_recomputeFeature(DocumentObject* Feat) void Document::recomputeFeature(DocumentObject* Feat) { - _checkTransaction(); - // delete recompute log for( std::vector::iterator it=_RecomputeLog.begin();it!=_RecomputeLog.end();++it) delete *it; @@ -1300,8 +1298,6 @@ DocumentObject * Document::addObject(const char* sType, const char* pObjectName) void Document::_addObject(DocumentObject* pcObject, const char* pObjectName) { - _checkTransaction(); - d->objectMap[pObjectName] = pcObject; d->objectArray.push_back(pcObject); // cache the pointer to the name string in the Object (for performance of DocumentObject::getNameInDocument()) diff --git a/src/App/Document.h b/src/App/Document.h index cca26ecdcd..dcf56d670d 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -260,7 +260,7 @@ protected: void _remObject(DocumentObject* pcObject); void _addObject(DocumentObject* pcObject, const char* pObjectName); DocumentObject* _copyObject(DocumentObject* obj, std::map&, bool rcursive=false); + DocumentObject*>&, bool recursive=false); /// checks if a valid transaction is open void _checkTransaction(void); void breakDependency(DocumentObject* pcObject, bool clear); diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index 3d3189dbad..981149fb46 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -47,6 +47,15 @@ class DocumentBasicCases(unittest.TestCase): self.Doc.commitTransaction() self.Doc.undo() + def testAddRemoveUndo(self): + # Bug #0000525 + self.Doc.openTransaction("Add") + obj=self.Doc.addObject("App::FeatureTest","Label") + self.Doc.commitTransaction() + self.Doc.removeObject(obj.Name) + self.Doc.undo() + self.Doc.undo() + def testRemoval(self): # Cannot write a real test case for that but when debugging the # C-code there shouldn't be a memory leak (see rev. 1814)