Python scripting: fix a crash with some pythons scripts calling BOARD::ComputeBoundingBox()

This function calls Pgm(), but when running from a script (not from kicad) Pgm() uses a nullptr reference.
The nullptr reference is now tested in ComputeBoundingBox()
This commit is contained in:
jean-pierre charras 2019-10-05 10:39:12 +02:00
parent b33c3a5ad8
commit 0a829c328e
4 changed files with 23 additions and 1 deletions

View File

@ -105,6 +105,14 @@ PGM_BASE& Pgm()
}
// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face
// is run from a python script, mot from a Kicad application
PGM_BASE* PgmOrNull()
{
return process;
}
//!!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
FP_LIB_TABLE GFootprintTable;

View File

@ -424,4 +424,9 @@ protected:
/// Implemented in: 1) common/single_top.cpp, 2) kicad/kicad.cpp, and 3) scripting/kiway.i
extern PGM_BASE& Pgm();
/// similat to PGM_BASE& Pgm(), but return a reference that can be nullptr
/// when running a shared lib from a script, not from a kicad appl
extern PGM_BASE* PgmOrNull();
#endif // PGM_BASE_H_

View File

@ -761,7 +761,8 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
{
EDA_RECT area;
LSET visible = GetVisibleLayers();
bool showInvisibleText = IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) && !Pgm().m_Printing;
bool showInvisibleText = IsElementVisible( LAYER_MOD_TEXT_INVISIBLE )
&& PgmOrNull() && !PgmOrNull()->m_Printing;
// Check segments, dimensions, texts, and fiducials
for( auto item : m_drawings )

View File

@ -192,6 +192,14 @@ PGM_BASE& Pgm()
wxASSERT( process ); // KIFACE_GETTER has already been called.
return *process;
}
// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face
// is run from a python script, mot from a Kicad application
PGM_BASE* PgmOrNull()
{
return process;
}
#endif