Browse Source

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()
pull/15/head
jean-pierre charras 6 years ago
parent
commit
0a829c328e
  1. 8
      cvpcb/cvpcb.cpp
  2. 5
      include/pgm_base.h
  3. 3
      pcbnew/class_board.cpp
  4. 8
      pcbnew/pcbnew.cpp

8
cvpcb/cvpcb.cpp

@ -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;

5
include/pgm_base.h

@ -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_

3
pcbnew/class_board.cpp

@ -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 )

8
pcbnew/pcbnew.cpp

@ -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

Loading…
Cancel
Save