FreeCAD icon indicating copy to clipboard operation
FreeCAD copied to clipboard

PD: Fix crash when adding sketch to loft via tree view

Open wwmayer opened this issue 1 year ago • 2 comments

The underlying problem is the method DocumentItem::updateItemSelection() where the selection is altered. This may cause the destruction and recreation of the DocumentObjectItems so that the passed pointer can become dangling.

The issue is fixed in two steps:

  1. Add the method 'DocumentObjectItem findItem(App::DocumentObject obj, const std::string& subname) const' to safely re-access the item.
  2. Add a boolean flag 'dirtyFlag' and the methods insertItem() and removeItem() to DocumentObjectData. This is needed to check when the iterator over the container becomes invalid.

wwmayer avatar Apr 27 '24 19:04 wwmayer

Fixes https://github.com/FreeCAD/FreeCAD/issues/13107

wwmayer avatar Apr 27 '24 19:04 wwmayer

Comment to https://github.com/FreeCAD/FreeCAD/pull/13682: That PR makes the crash disappear by not calling the function that triggers the problem in DocumentItem::updateItemSelection(). So to speak it cures the symptoms but doesn't fix the root of the problem. Nevertheless, there is nothing wrong with the PR and it's fine to merge it, too.

wwmayer avatar Apr 27 '24 22:04 wwmayer