Summary of problem description
MITK crashes when unchecking the Show Position Nodes checkbox in the segmentation.
Actual behavior
Start ExtApp and create a new segmentation
Uncheck the Show Position Nodes checkbox -> crash
Expected behavior
No crash should happen
Cause of the bug
In QmitkDataStorageTreeModel an observer is registered on newly added nodes which hold the property helper object. This observer invokes an update of the TreeModel every time the value of the property is changed. If the value is changed to false a node which was previously a helper object should be displayed now and hence must be added to the TreeModel.
In order to avoid crash situations and memory leaks the observers are removed in the destructor of the QmitkDataStorageTreeModel. Since nodes can be deleted during runtime by user-interaction the observers of these deleted nodes must be removed too when the node is deleted. This is done in the RemoveNode method of QmitkDataStorageTreeModel which is called by the QmitkDataManagerView every time a node is deleted. Unfortunately the RemoveNode method is not just called if a node is deleted from the DataStorage but also if the preferences of the DataManager change (e.g. Show Helper Objects) or the helper object of a node is changed. The AddNode method works similar. If just the properties or the preferences change then the observer of course should NOT be removed from a node. In the case of a changed property value MITK even crashes.
Proposed solution
There must be two different methods for each removing and adding nodes: If nodes are added or removed from the data storage there must be two method in the TreeModel. Additional to that we need functions for adding/removing nodes if properties/preferences have changed, i.e. just updating the TreeModel. The proposed solution is:
write two new methods: AddNodeInternal, RemoveNodeInternal
moved the code from the former AddNode and RemoveNode to the internal ones except the part that adds/removes the observers (since this should be done in case a new node is added to the data storage or removed from it)
After adding/removing the observers the old methods call the new internal ones in order to update the TreeModel.
The Update() function of the QmitkDataStorageTreeModel now calls the new internal methods
The QmitkDataManager still calls the old old ones.
All observers are now removed correctly (if a node is deleted during runtime and in the destructor of the TreeModel)
Affected classes
QmitkDataStorageTreeModel
How will the bugfix get tested?
This is probably not the best solution but a quick fix to avoid a crash. I will mention this issue in the next MITK-meeting. I tested all scenarios:
- create a segmentation and check/uncheck the checkbox
create a segmentation and click into one slice -> PositionNode appears
then delete PositionNode and close application
create a segmentation and click into one slice -> PositionNode appears
- then close application
- create segmentation and draw several contour in different slices. For each slice a
PositionNode should appear. Delete randomly some nodes and create new ones. Then close application
changed the property of the DataManager to Show Helper Objects and Show Nodes Containing No Data
In neither situation MITK crashed
