Try to prevent a crash in mpFXY::Plot

Fixes sentry kicad-c0
This commit is contained in:
Marek Roszko 2023-02-19 00:38:42 -05:00
parent 9b708ce6d1
commit c5a2c9c773
1 changed files with 20 additions and 16 deletions

View File

@ -328,7 +328,7 @@ void mpInfoLegend::Plot( wxDC& dc, mpWindow& w )
int plotCount = 0; int plotCount = 0;
int posY = 0; int posY = 0;
int tmpX = 0, tmpY = 0; int tmpX = 0, tmpY = 0;
mpLayer* ly = NULL; mpLayer* ly = nullptr;
wxPen lpen; wxPen lpen;
wxString label; wxString label;
@ -542,8 +542,8 @@ mpFXY::mpFXY( const wxString& name, int flags )
SetName( name ); SetName( name );
m_flags = flags; m_flags = flags;
m_type = mpLAYER_PLOT; m_type = mpLAYER_PLOT;
m_scaleX = NULL; m_scaleX = nullptr;
m_scaleY = NULL; m_scaleY = nullptr;
// Avoid not initialized members: // Avoid not initialized members:
maxDrawX = minDrawX = maxDrawY = minDrawY = 0; maxDrawX = minDrawX = maxDrawY = minDrawY = 0;
@ -563,6 +563,10 @@ void mpFXY::UpdateViewBoundary( wxCoord xnew, wxCoord ynew )
void mpFXY::Plot( wxDC& dc, mpWindow& w ) void mpFXY::Plot( wxDC& dc, mpWindow& w )
{ {
wxCHECK_RET( m_scaleX, wxS( "X scale was not set" ) );
wxCHECK_RET( m_scaleY, wxS( "Y scale was not set" ) );
if( m_visible ) if( m_visible )
{ {
dc.SetPen( m_pen ); dc.SetPen( m_pen );
@ -1396,7 +1400,7 @@ mpScaleY::mpScaleY( const wxString& name, int flags, bool ticks )
m_flags = flags; m_flags = flags;
m_ticks = ticks; m_ticks = ticks;
m_type = mpLAYER_AXIS; m_type = mpLAYER_AXIS;
m_masterScale = NULL; m_masterScale = nullptr;
m_nameFlags = mpALIGN_BORDER_LEFT; m_nameFlags = mpALIGN_BORDER_LEFT;
} }
@ -1667,11 +1671,11 @@ mpWindow::mpWindow( wxWindow* parent,
m_minX = m_minY = 0; m_minX = m_minY = 0;
m_maxX = m_maxY = 0; m_maxX = m_maxY = 0;
m_last_lx = m_last_ly = 0; m_last_lx = m_last_ly = 0;
m_buff_bmp = NULL; m_buff_bmp = nullptr;
m_enableDoubleBuffer = false; m_enableDoubleBuffer = false;
m_enableMouseNavigation = true; m_enableMouseNavigation = true;
m_enableLimitedView = false; m_enableLimitedView = false;
m_movingInfoLayer = NULL; m_movingInfoLayer = nullptr;
// Set margins to 0 // Set margins to 0
m_marginTop = 0; m_marginRight = 0; m_marginBottom = 0; m_marginLeft = 0; m_marginTop = 0; m_marginRight = 0; m_marginBottom = 0; m_marginLeft = 0;
@ -1919,10 +1923,10 @@ void mpWindow::OnMouseLeftRelease( wxMouseEvent& event )
m_zooming = false; m_zooming = false;
if( m_movingInfoLayer != NULL ) if( m_movingInfoLayer != nullptr )
{ {
m_movingInfoLayer->UpdateReference(); m_movingInfoLayer->UpdateReference();
m_movingInfoLayer = NULL; m_movingInfoLayer = nullptr;
} }
else else
{ {
@ -1958,7 +1962,7 @@ void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax,
yMin -= yExtra; yMin -= yExtra;
yMax += yExtra; yMax += yExtra;
if( printSizeX != NULL && printSizeY != NULL ) if( printSizeX != nullptr && printSizeY != nullptr )
{ {
// Printer: // Printer:
m_scrX = *printSizeX; m_scrX = *printSizeX;
@ -1999,7 +2003,7 @@ void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax,
// It is VERY IMPORTANT to DO NOT call Refresh if we are drawing to the printer!! // It is VERY IMPORTANT to DO NOT call Refresh if we are drawing to the printer!!
// Otherwise, the DC dimensions will be those of the window instead of the printer device // Otherwise, the DC dimensions will be those of the window instead of the printer device
if( printSizeX == NULL || printSizeY == NULL ) if( printSizeX == nullptr || printSizeY == nullptr )
UpdateAll(); UpdateAll();
} }
@ -2634,7 +2638,7 @@ unsigned int mpWindow::CountLayers() const
mpLayer* mpWindow::GetLayer( int position ) const mpLayer* mpWindow::GetLayer( int position ) const
{ {
if( ( position >= (int) m_layers.size() ) || position < 0 ) if( ( position >= (int) m_layers.size() ) || position < 0 )
return NULL; return nullptr;
return m_layers[position]; return m_layers[position];
} }
@ -2648,7 +2652,7 @@ const mpLayer* mpWindow::GetLayerByName( const wxString& name ) const
return layer; return layer;
} }
return NULL; // Not found return nullptr; // Not found
} }
@ -2735,7 +2739,7 @@ mpInfoLayer* mpWindow::IsInsideInfoLayer( wxPoint& point )
} }
} }
return NULL; return nullptr;
} }
@ -3078,9 +3082,9 @@ bool mpPrintout::OnPrintPage( int page )
// Restore colours // Restore colours
plotWindow->SetColourTheme( oldBgColour, oldFgColour, oldAxColour ); plotWindow->SetColourTheme( oldBgColour, oldFgColour, oldAxColour );
// Restore drawing // Restore drawing
plotWindow->Fit( plotWindow->GetDesiredXmin(), plotWindow->Fit( plotWindow->GetDesiredXmin(), plotWindow->GetDesiredXmax(),
plotWindow->GetDesiredXmax(), plotWindow->GetDesiredYmin(), plotWindow->GetDesiredYmin(), plotWindow->GetDesiredYmax(), nullptr,
plotWindow->GetDesiredYmax(), NULL, NULL ); nullptr );
plotWindow->UpdateAll(); plotWindow->UpdateAll();
} }