From d68536fb49f30f1036f5e879c04705fd18279e22 Mon Sep 17 00:00:00 2001 From: inv Date: Thu, 4 Oct 2012 10:37:14 +0000 Subject: [PATCH] 0021769: EDF OCCT: Closing the OCC viewer leads to SIGSEGV (OCCT dev) --- src/OCCViewer/OCCViewer_ViewModel.cxx | 16 ++++++++++++++++ src/OCCViewer/OCCViewer_ViewModel.h | 1 + src/OCCViewer/OCCViewer_ViewPort3d.cxx | 1 + src/OCCViewer/OCCViewer_ViewPort3d.h | 1 + 4 files changed, 19 insertions(+) diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index a4f2bb86d..170b843e6 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -169,6 +169,9 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron) */ OCCViewer_Viewer::~OCCViewer_Viewer() { + myAISContext.Nullify(); + myV3dViewer.Nullify(); + myV3dCollector.Nullify(); } /*! @@ -240,6 +243,8 @@ SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop ) initView( vw ); // set default background for view window vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here) + // connect signal from viewport + connect(view->getViewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed())); return view; } @@ -370,6 +375,17 @@ void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEven emit selectionChanged(); } +void OCCViewer_Viewer::onViewClosed() +{ + Standard_Integer aViewsNb = 0; + for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews()) + ++aViewsNb; + if ( aViewsNb < 2 ) { + //clean up presentations before last view is closed + myAISContext->RemoveAll(Standard_False); + } +} + int OCCViewer_Viewer::getTopLayerId() { #if OCC_VERSION_LARGE > 0x06050200 diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index 90f128c23..46c1e4786 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -163,6 +163,7 @@ protected slots: virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*); virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*); + virtual void onViewClosed(); void onDumpView(); void onChangeBackground(); diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index 26b0736b2..3dd08a812 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -92,6 +92,7 @@ OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_V */ OCCViewer_ViewPort3d::~OCCViewer_ViewPort3d() { + emit vpClosed(); Handle(V3d_View) aView = activeView(); if (!aView.IsNull()) aView->Remove(); diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.h b/src/OCCViewer/OCCViewer_ViewPort3d.h index 17847bc3d..d82872979 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.h +++ b/src/OCCViewer/OCCViewer_ViewPort3d.h @@ -96,6 +96,7 @@ public: signals: void vpChangeBackground( const Qtx::BackgroundData& ); + void vpClosed(); public slots: virtual bool synchronize( OCCViewer_ViewPort* ); -- 2.39.2