From 89faa7bdc95cd3d8a2ccbb9d2e59de4a2da4eee1 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 31 Jul 2014 11:23:39 +0400 Subject: [PATCH] Prevent crash when viewer opened --- src/PartSet/PartSet_Module.cpp | 22 ++++++++++++---------- src/XGUI/XGUI_Viewer.cpp | 4 +++- src/XGUI/XGUI_ViewerProxy.cpp | 7 +++++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index b28152c01..611d2a5fd 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -214,13 +214,14 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent) { PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( myWorkshop->operationMgr()->currentOperation()); - if (aPreviewOp) { + Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); + if (aPreviewOp && (!aView.IsNull())) { XGUI_Selection* aSelection = myWorkshop->selector()->selection(); // Initialise operation with preliminary selection std::list aSelected = aSelection->getSelected(); std::list aHighlighted = aSelection->getHighlighted(); - aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); + aPreviewOp->mousePressed(theEvent, aView, aSelected, aHighlighted); } } @@ -228,13 +229,14 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) { PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( myWorkshop->operationMgr()->currentOperation()); - if (aPreviewOp) { + Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); + if (aPreviewOp && (!aView.IsNull())) { XGUI_Selection* aSelection = myWorkshop->selector()->selection(); // Initialise operation with preliminary selection std::list aSelected = aSelection->getSelected(); std::list aHighlighted = aSelection->getHighlighted(); - aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); + aPreviewOp->mouseReleased(theEvent, aView, aSelected, aHighlighted); } } @@ -242,8 +244,9 @@ void PartSet_Module::onMouseMoved(QMouseEvent* theEvent) { PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( myWorkshop->operationMgr()->currentOperation()); - if (aPreviewOp) - aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView()); + Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); + if (aPreviewOp && (!aView.IsNull())) + aPreviewOp->mouseMoved(theEvent, aView); } void PartSet_Module::onKeyRelease(QKeyEvent* theEvent) @@ -259,14 +262,13 @@ void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent) { PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( myWorkshop->operationMgr()->currentOperation()); - if (aPreviewOp) - { + Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); + if (aPreviewOp && (!aView.IsNull())) { XGUI_Selection* aSelection = myWorkshop->selector()->selection(); // Initialise operation with preliminary selection std::list aSelected = aSelection->getSelected(); std::list aHighlighted = aSelection->getHighlighted(); - aPreviewOp->mouseDoubleClick(theEvent, myWorkshop->viewer()->activeView(), aSelected, - aHighlighted); + aPreviewOp->mouseDoubleClick(theEvent, aView, aSelected, aHighlighted); } } diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index ff33f60eb..549b3e449 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -197,7 +197,9 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType) XGUI_ViewWindow* XGUI_Viewer::activeViewWindow() const { - return dynamic_cast(myActiveView->widget()); + if (myActiveView) + return dynamic_cast(myActiveView->widget()); + return 0; } void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList) diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index 19453efdb..65c21fc58 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -37,7 +37,9 @@ Handle(V3d_View) XGUI_ViewerProxy::activeView() const return myWorkshop->salomeConnector()->viewer()->activeView(); } else { XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); - return aViewer->activeViewWindow()->viewPort()->getView(); + return (aViewer->activeViewWindow())? + aViewer->activeViewWindow()->viewPort()->getView(): + Handle(V3d_View)(); } } @@ -58,7 +60,8 @@ void XGUI_ViewerProxy::fitAll() } else { XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); - aViewer->activeViewWindow()->viewPort()->fitAll(); + if (aViewer->activeViewWindow()) + aViewer->activeViewWindow()->viewPort()->fitAll(); } } -- 2.39.2