std::shared_ptr<ModelAPI_Session> aPM = Model_Session::get();
if (this != aPM->moduleDocument().get() && this == aPM->activeDocument().get()) {
aPM->setActiveDocument(aPM->moduleDocument());
+ } else if (this == aPM->moduleDocument().get()) {
+ // erase the active document if root is closed
+ aPM->setActiveDocument(DocumentPtr());
}
// close all subs
const std::set<std::string> aSubs = subDocuments(true);
{
if (myCurrentDoc != theDoc) {
myCurrentDoc = theDoc;
- if (theSendSignal) {
+ if (theDoc.get() && theSendSignal) {
// syncronize the document: it may be just opened or opened but removed before
std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theDoc);
- if (aDoc) {
+ if (aDoc.get()) {
bool aWasChecked = myCheckTransactions;
setCheckTransactions(false);
aDoc->synchronizeFeatures(false, true);