From 9d4042baced423dc46a5967d042225cba4fdba50 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Mon, 12 Oct 2020 09:43:08 +0200 Subject: [PATCH] fix bug abort on import image, several random cases related to using already deleted object --- src/HYDROGUI/HYDROGUI_Displayer.cxx | 8 ++++ src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx | 2 +- src/HYDROGUI/HYDROGUI_ImportImageOp.cxx | 48 ++++++++++++++++++++++-- src/HYDROGUI/HYDROGUI_Module.cxx | 2 +- src/HYDROGUI/HYDROGUI_PrsImage.cxx | 5 +++ 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index c869d87c..adf3c87d 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -42,6 +42,9 @@ #include #include +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" + const double LOCAL_SELECTION_TOLERANCE = 0.0001; HYDROGUI_Displayer::HYDROGUI_Displayer( HYDROGUI_Module* theModule ) @@ -156,7 +159,10 @@ void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs, if( HYDROGUI_PrsDriver* aDriver = getDriver( anObj ) ) { if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted ) + { + DEBTRACE("Display, addItem"); aViewPort->addItem( aPrs ); + } } } @@ -176,6 +182,7 @@ void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs, void HYDROGUI_Displayer::purgeObjects( const size_t theViewerId ) { + DEBTRACE("purgeObjects"); GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId ); if( !aViewer ) return; @@ -192,6 +199,7 @@ void HYDROGUI_Displayer::purgeObjects( const size_t theViewerId ) Handle(HYDROData_Entity) anObject = aPrs->getObject(); if( !anObject.IsNull() && anObject->IsRemoved() ) { + DEBTRACE("removeItem"); aViewPort->removeItem( aPrs ); delete aPrs; } diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx index e238f569..4922ee13 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx @@ -1042,7 +1042,7 @@ void HYDROGUI_ImportImageDlg::clearSpins( QAbstractSpinBox* theSpin ) QtxIntSpinBox* aSpin = dynamic_cast( theSpin ); aSpin->setValue( aSpin->minimum() ); } - else if ( dynamic_cast( theSpin ) ) + else if ( dynamic_cast( theSpin ) ) { QtxDoubleSpinBox* aDblSpin = dynamic_cast( theSpin ); aDblSpin->setValue( aDblSpin->minimum() ); diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index eef9bd9a..5b16a0e4 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -43,6 +43,9 @@ #include #include +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" + HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule, const bool theIsEdit ) : HYDROGUI_Operation( theModule ), @@ -55,17 +58,27 @@ HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule, myRefPreviewPrs( 0 ), myPointType( HYDROGUI_PrsImage::None ) { + DEBTRACE("HYDROGUI_ImportImageOp"); setName( theIsEdit ? tr( "EDIT_IMPORTED_IMAGE" ) : tr( "IMPORT_IMAGE" ) ); } HYDROGUI_ImportImageOp::~HYDROGUI_ImportImageOp() { + DEBTRACE("~HYDROGUI_ImportImageOp"); } void HYDROGUI_ImportImageOp::startOperation() { + DEBTRACE("startOperation"); HYDROGUI_Operation::startOperation(); + myEditedObject = 0; + myActiveViewManager = 0; + myPreviewViewManager = 0; + myRefViewManager = 0; + myPreviewPrs = 0; + myRefPreviewPrs = 0; + myPointType = HYDROGUI_PrsImage::None; HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); aPanel->reset(); aPanel->setIsEdit( myIsEdit ); @@ -177,6 +190,7 @@ void HYDROGUI_ImportImageOp::setPresentationTrsfPoints( HYDROGUI_PrsImage* thePr const QPoint theLocalPointB, const QPoint theLocalPointC ) { + DEBTRACE("setPresentationTrsfPoints"); // Set transformation points A,B,C to the image presentation if( thePrs ) { @@ -198,6 +212,7 @@ void HYDROGUI_ImportImageOp::setPresentationTrsfPoints( HYDROGUI_PrsImage* thePr void HYDROGUI_ImportImageOp::getReferenceDataList( HYDROGUI_ImportImageDlg::PrsPointDataList& theList ) const { + DEBTRACE("getReferenceDataList"); // Collect information about existing images and initialize the combobox // reference image selector in the dialog. HYDROData_Iterator anIterator( doc(), KIND_IMAGE ); @@ -237,6 +252,7 @@ void HYDROGUI_ImportImageOp::computeTrsfData( HYDROData_Image::TransformationMod const QPointF& theGlobalPointC, HYDROGUI_ImportImageDlg::TransformationDataMap& theDataMap ) const { + DEBTRACE("computeTrsfData"); // Build the local-global points map HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap; theDataMap[ HYDROGUI_PrsImage::PointA ] = @@ -252,13 +268,14 @@ void HYDROGUI_ImportImageOp::computeTrsfData( HYDROData_Image::TransformationMod void HYDROGUI_ImportImageOp::abortOperation() { + DEBTRACE("abortOperation"); closePreview(); - HYDROGUI_Operation::abortOperation(); } void HYDROGUI_ImportImageOp::commitOperation() { + DEBTRACE("commitOperation"); if ( isApplyAndClose() ) closePreview(); @@ -267,6 +284,7 @@ void HYDROGUI_ImportImageOp::commitOperation() HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const { + DEBTRACE("createInputPanel"); HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() ); connect( aPanel, SIGNAL( createPreview( QImage, HYDROData_Image::ECW_FileInfo* ) ), SLOT( onCreatePreview( QImage, HYDROData_Image::ECW_FileInfo* ) ) ); @@ -284,6 +302,7 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const void HYDROGUI_ImportImageOp::onSetCIsUsed( bool theCIsUsed ) { + DEBTRACE("onSetCIsUsed"); if ( myPreviewPrs ) { myPreviewPrs->setIsByTwoPoints( !theCIsUsed ); @@ -303,6 +322,7 @@ bool HYDROGUI_ImportImageOp::checkPoints( const QPointF& thePointA, QString& theErrorMsg, const bool theIsToCheckInvertibles ) const { + DEBTRACE("checkPoints"); double xa = thePointA.x(); double ya = thePointA.y(); double xb = thePointB.x(); @@ -349,6 +369,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries ) { + DEBTRACE("processApply"); HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); if( !myIsEdit ) @@ -512,7 +533,10 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, // must be done after all checks and before calling SetVisible() method below if ( isApplyAndClose() ) + { + DEBTRACE("closePreview"); closePreview(); + } if( !myIsEdit ) module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true ); @@ -545,6 +569,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, bool HYDROGUI_ImportImageOp::isReferenceCorrect() const { + DEBTRACE("isReferenceCorrect"); bool isCorrect = true; if( myIsEdit && !myEditedObject.IsNull() ) @@ -569,6 +594,7 @@ bool HYDROGUI_ImportImageOp::isReferenceCorrect() const void HYDROGUI_ImportImageOp::apply() { + DEBTRACE("apply"); HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); bool aCanApply = isReferenceCorrect(); @@ -592,6 +618,7 @@ void HYDROGUI_ImportImageOp::apply() void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage, HYDROData_Image::ECW_FileInfo* theFileInfo ) { + DEBTRACE("onCreatePreview"); HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); myImage = theImage; @@ -699,6 +726,7 @@ void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage, HYDROData_Image:: void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType ) { + DEBTRACE("onActivatePointSelection"); myPointType = thePointType; if( myPreviewPrs ) myPreviewPrs->setTransformationPointType( thePointType ); @@ -711,6 +739,7 @@ void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef, bool theIsY, int theValue ) { + DEBTRACE("onPointCoordChanged"); if( !theIsRef && myPreviewPrs ) myPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue ); else if( theIsRef && myRefPreviewPrs ) @@ -719,6 +748,7 @@ void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef, void HYDROGUI_ImportImageOp::onModeActivated( int theMode ) { + DEBTRACE("onModeActivated"); HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); QString aRefImageName; @@ -740,6 +770,7 @@ void HYDROGUI_ImportImageOp::onModeActivated( int theMode ) void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName ) { + DEBTRACE("onRefImageActivated"); if( theName.isEmpty() ) { if( myRefViewManager ) closeView( myRefViewManager ); @@ -842,21 +873,25 @@ void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName ) void HYDROGUI_ImportImageOp::onLastViewClosed( SUIT_ViewManager* theViewManager ) { + DEBTRACE("onLastViewClosed"); closePreview(); } void HYDROGUI_ImportImageOp::onPointSelected() { + DEBTRACE("onPointSelected"); onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() ); } void HYDROGUI_ImportImageOp::onRefPointSelected() { + DEBTRACE("onRefPointSelected"); onPointSelected( true ); } void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage ) { + DEBTRACE("onPointSelected"); HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs; if( !aPrs ) return; @@ -882,6 +917,7 @@ void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage ) void HYDROGUI_ImportImageOp::closePreview() { + DEBTRACE("closePreview"); closeView( myPreviewViewManager ); closeView( myRefViewManager ); @@ -891,6 +927,7 @@ void HYDROGUI_ImportImageOp::closePreview() void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr ) { + DEBTRACE("closeView"); if( aViewMgr ) { GraphicsView_ViewPort* aViewPort = 0; @@ -915,9 +952,12 @@ void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr ) } // Remove the appropriate presentation from the view - if( aPrs && aViewPort ) + if( aPrs ) { - aViewPort->removeItem( aPrs ); + if( aViewPort ) + { + aViewPort->removeItem( aPrs ); + } delete aPrs; } @@ -929,6 +969,7 @@ void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr ) void HYDROGUI_ImportImageOp::onFilesSelected( const QStringList& theFileNames ) { + DEBTRACE("onFilesSelected"); myFiles = theFileNames; myFileIndex = -1; SetNextFile(); @@ -936,6 +977,7 @@ void HYDROGUI_ImportImageOp::onFilesSelected( const QStringList& theFileNames ) bool HYDROGUI_ImportImageOp::SetNextFile() { + DEBTRACE("SetNextFile"); myFileIndex++; bool isEnabledEdit = myFiles.count()==1 || myFileIndex==myFiles.count(); bool isValid = ( myFileIndex>=0 && myFileIndex #include -//#define _DEVDEBUG_ +#define _DEVDEBUG_ #include "HYDRO_trace.hxx" static size_t ViewManagerId = 1; diff --git a/src/HYDROGUI/HYDROGUI_PrsImage.cxx b/src/HYDROGUI/HYDROGUI_PrsImage.cxx index a146d254..6a5fe4a1 100644 --- a/src/HYDROGUI/HYDROGUI_PrsImage.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsImage.cxx @@ -25,6 +25,9 @@ #include #include +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" + //======================================================================= // name : HYDROGUI_PrsImage // Purpose : Constructor @@ -38,6 +41,7 @@ HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Entity)& theObject myIsByTwoPoints( true ), myTransformationPointType( None ) { + DEBTRACE("HYDROGUI_PrsImage"); myTransformationPointCursor = new QCursor( Qt::CrossCursor ); } @@ -47,6 +51,7 @@ HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Entity)& theObject //======================================================================= HYDROGUI_PrsImage::~HYDROGUI_PrsImage() { + DEBTRACE("~HYDROGUI_PrsImage"); if( myTransformationPointCursor ) { delete myTransformationPointCursor; -- 2.39.2