There are several places in the code that have the following pattern:
if(!weakPointer.IsExpired()) { smartPointer = weakPointer.Lock(); //do something with the smartPointer }
This is not safe. As you have no guarantee that the weakPointer is valid in the next line. If you plan to use the weakPointer and want to be sure that you can use it, you have to do the following:
smartPointer = weakPointer.Lock(); if(smartPointer.IsNotNull()) { //do your stuff }
In addition we should extend the documentation of mitk::WeakPointer::IsExpired() to stress the correct behavior. You should IsExpired() if you realy just want to know if the pointer is gone or not.