BUG: Make sure the node is present before saving in a collection

While updating the scene, the tree view hierarchy was being saved. This causes
segfaults when updateScene is called after closing the scene or deleting nodes.
Check if the nodes are still present before saving them to collection.
Fixes issue 2557.