PD: Fix crash when adding sketch to loft via tree view
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:
- Add the method 'DocumentObjectItem findItem(App::DocumentObject obj, const std::string& subname) const' to safely re-access the item.
- 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.
Fixes https://github.com/FreeCAD/FreeCAD/issues/13107
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.