Don't crash when OCC fails to read a model and didn't open the doc.

This commit is contained in:
Alex Shvartzkop 2023-12-06 03:16:43 +03:00
parent 26c8c718eb
commit 9345b73af5
2 changed files with 43 additions and 20 deletions

View File

@ -209,7 +209,8 @@ STEP_PCB_MODEL::STEP_PCB_MODEL( const wxString& aPcbName )
STEP_PCB_MODEL::~STEP_PCB_MODEL()
{
m_doc->Close();
if( m_doc->CanClose() == CDM_CCS_OK )
m_doc->Close();
}
bool STEP_PCB_MODEL::AddPadShape( const PAD* aPad, const VECTOR2D& aOrigin )
@ -1467,14 +1468,18 @@ bool STEP_PCB_MODEL::readIGES( Handle( TDocStd_Document )& doc, const char* fnam
if( !reader.Transfer( doc ) )
{
doc->Close();
if( doc->CanClose() == CDM_CCS_OK )
doc->Close();
return false;
}
// are there any shapes to translate?
if( reader.NbShapes() < 1 )
{
doc->Close();
if( doc->CanClose() == CDM_CCS_OK )
doc->Close();
return false;
}
@ -1505,14 +1510,18 @@ bool STEP_PCB_MODEL::readSTEP( Handle( TDocStd_Document )& doc, const char* fnam
if( !reader.Transfer( doc ) )
{
doc->Close();
if( doc->CanClose() == CDM_CCS_OK )
doc->Close();
return false;
}
// are there any shapes to translate?
if( reader.NbRootsForTransfer() < 1 )
{
doc->Close();
if( doc->CanClose() == CDM_CCS_OK )
doc->Close();
return false;
}

View File

@ -553,12 +553,22 @@ bool readIGES( Handle( TDocStd_Document ) & m_doc, const char* fname )
reader.SetNameMode(false); // don't use IGES label names
reader.SetLayerMode(false); // ignore LAYER data
if ( !reader.Transfer( m_doc ) )
if( !reader.Transfer( m_doc ) )
{
if( m_doc->CanClose() == CDM_CCS_OK )
m_doc->Close();
return false;
}
// are there any shapes to translate?
if( reader.NbShapes() < 1 )
{
if( m_doc->CanClose() == CDM_CCS_OK )
m_doc->Close();
return false;
}
return true;
}
@ -587,15 +597,22 @@ bool readSTEP( Handle(TDocStd_Document)& m_doc, const char* fname )
reader.SetNameMode( false ); // don't use label names
reader.SetLayerMode( false ); // ignore LAYER data
if ( !reader.Transfer( m_doc ) )
if( !reader.Transfer( m_doc ) )
{
m_doc->Close();
if( m_doc->CanClose() == CDM_CCS_OK )
m_doc->Close();
return false;
}
// are there any shapes to translate?
if( reader.NbRootsForTransfer() < 1 )
{
if( m_doc->CanClose() == CDM_CCS_OK )
m_doc->Close();
return false;
}
return true;
}
@ -685,34 +702,27 @@ SCENEGRAPH* LoadModel( char const* filename )
data.renderBoth = true;
if( !readIGES( data.m_doc, filename ) )
{
m_app->Close( data.m_doc );
return nullptr;
}
break;
case FMT_STEP:
if( !readSTEP( data.m_doc, filename ) )
{
m_app->Close( data.m_doc );
return nullptr;
}
break;
case FMT_STPZ:
if( !readSTEPZ( data.m_doc, filename ) )
{
m_app->Close( data.m_doc );
return nullptr;
}
break;
default:
m_app->Close( data.m_doc );
if( m_app->CanClose( data.m_doc ) == CDM_CCS_OK )
m_app->Close( data.m_doc );
return nullptr;
break;
}
@ -749,7 +759,9 @@ SCENEGRAPH* LoadModel( char const* filename )
if( !ret )
{
m_app->Close( data.m_doc );
if( m_app->CanClose( data.m_doc ) == CDM_CCS_OK )
m_app->Close( data.m_doc );
return nullptr;
}
@ -776,7 +788,9 @@ SCENEGRAPH* LoadModel( char const* filename )
// set to NULL to prevent automatic destruction of the scene data
data.scene = nullptr;
m_app->Close( data.m_doc );
if( m_app->CanClose( data.m_doc ) == CDM_CCS_OK )
m_app->Close( data.m_doc );
return scene;
}