Wed, 18 Dec 2013 20:43:50 +0200
- fixed: LDObject methods still used operator delete directly, causing *a very frustrating* crash to debug
src/document.cc | file | annotate | diff | comparison | revisions | |
src/history.cc | file | annotate | diff | comparison | revisions | |
src/ldtypes.cc | file | annotate | diff | comparison | revisions |
--- a/src/document.cc Wed Dec 18 19:39:55 2013 +0200 +++ b/src/document.cc Wed Dec 18 20:43:50 2013 +0200 @@ -872,7 +872,7 @@ #ifdef DEBUG if (!isImplicit()) - dlog ("Added object #%1\n", obj->getID()); + dlog ("Added object #%1 (%2)\n", obj->getID(), obj->getTypeName()); #endif obj->setFile (this); @@ -893,6 +893,11 @@ { getHistory()->add (new AddHistory (pos, obj)); m_Objects.insert (pos, obj); obj->setFile (this); + +#ifdef DEBUG + if (!isImplicit()) + dlog ("Inserted object #%1 (%2) at %3\n", obj->getID(), obj->getTypeName(), pos); +#endif } // =============================================================================
--- a/src/history.cc Wed Dec 18 19:39:55 2013 +0200 +++ b/src/history.cc Wed Dec 18 20:43:50 2013 +0200 @@ -38,7 +38,6 @@ const Changeset& set = getChangeset (getPosition()); g_fullRefresh = false; - dlog ("History: performing undo: set has %1 changes", set.size()); // Iterate the list in reverse and undo all actions for (int i = set.size() - 1; i >= 0; --i) @@ -78,6 +77,7 @@ g_win->doFullRefresh(); g_win->updateActions(); + dlog ("Position is now %1", getPosition()); } // ============================================================================= @@ -97,7 +97,6 @@ { if (m_currentChangeset.isEmpty()) return; - dlog ("position: %1, size: %2\n", getPosition(), getSize()); while (getPosition() < getSize() - 1) { Changeset last = m_changesets.last(); @@ -118,8 +117,7 @@ // ----------------------------------------------------------------------------- void History::add (AbstractHistoryEntry* entry) { if (isIgnoring()) - { dlog ("Ignored addition of history entry of type %1", entry->getTypeName()); - delete entry; + { delete entry; return; } @@ -132,7 +130,6 @@ // ----------------------------------------------------------------------------- void AddHistory::undo() const { LDObject* obj = getParent()->getFile()->getObject (getIndex()); - dlog ("History: undoing addition of #%1", obj->getID()); obj->deleteSelf(); g_fullRefresh = true; } @@ -147,20 +144,15 @@ // ============================================================================= // ----------------------------------------------------------------------------- -DelHistory::DelHistory (int idx, LDObject* obj) -{ dlog ("obj is: %1, code: %2", obj->getType(), obj->raw()); - setIndex (idx); - setCode (obj->raw()); -} +DelHistory::DelHistory (int idx, LDObject* obj) : + m_Index (idx), + m_Code (obj->raw()) {} // ============================================================================= // heh // ----------------------------------------------------------------------------- void DelHistory::undo() const -{ dlog ("code: %1", getCode()); - dlog ("index: %1", getIndex()); - LDObject* obj = parseLine (getCode()); - dlog( "new obj is of type %1 (%2)\n", obj->getType(), obj->getTypeName() ); +{ LDObject* obj = parseLine (getCode()); getParent()->getFile()->insertObj (getIndex(), obj); g_win->R()->compileObject (obj); } @@ -168,10 +160,8 @@ // ============================================================================= // ----------------------------------------------------------------------------- void DelHistory::redo() const -{ LDDocument* f = getParent()->getFile(); - LDObject* obj = f->getObject (getIndex()); +{ LDObject* obj = getParent()->getFile()->getObject (getIndex()); obj->deleteSelf(); - g_fullRefresh = true; }
--- a/src/ldtypes.cc Wed Dec 18 19:39:55 2013 +0200 +++ b/src/ldtypes.cc Wed Dec 18 20:43:50 2013 +0200 @@ -30,7 +30,7 @@ cfg (Int, ld_defaultlicense, 0); // List of all LDObjects -QList<LDObject*> g_LDObjects; +static QList<LDObject*> g_LDObjects; // ============================================================================= // LDObject constructors @@ -50,11 +50,14 @@ // ============================================================================= // ----------------------------------------------------------------------------- void LDObject::chooseID() -{ int32 id = 1; // 0 is invalid +{ int32 id = 1; // 0 shalt be null for (LDObject* obj : g_LDObjects) + { assert (obj != this); + if (obj->getID() >= id) id = obj->getID() + 1; + } setID (id); } @@ -228,7 +231,7 @@ getFile()->setObject (idx, other); // Remove the old object - delete this; + deleteSelf(); } // ============================================================================= @@ -271,9 +274,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void LDObject::deleteSelf() -{ dlog( "#%1: type: %2\n", getID(), getType()); - - // If this object was selected, unselect it now +{ // If this object was selected, unselect it now if (isSelected()) unselect(); @@ -399,7 +400,7 @@ str LDObject::typeName (LDObject::Type type) { LDObject* obj = LDObject::getDefault (type); str name = obj->getTypeName(); - delete obj; + obj->deleteSelf(); return name; } @@ -429,7 +430,6 @@ str noun = fmt ("%1%2", typeName (objType), plural (count)); // Plural of "vertex" is "vertices", correct that - if (objType == LDObject::Vertex && count != 1) noun = "vertices"; @@ -611,7 +611,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- LDObject* LDObject::fromID (int id) -{ for (LDObject * obj : g_LDObjects) +{ for (LDObject* obj : g_LDObjects) if (obj->getID() == id) return obj;