Fix a couple crashes with small canvases

The canvas size is not guaranteed to be strictly > 0, so we need to
enforce a minimum returned size before dividing by it or passing to GAL
initialization
This commit is contained in:
Seth Hillbrand 2020-03-04 14:33:42 -06:00
parent 011e4116d6
commit 12088f240d
3 changed files with 11 additions and 3 deletions

View File

@ -228,7 +228,9 @@ void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
{
KIGFX::GAL_CONTEXT_LOCKER locker( m_gal );
wxSize clientSize = GetClientSize();
m_gal->ResizeScreen( clientSize.x, clientSize.y );
clientSize.x = std::max( 10, clientSize.x );
clientSize.y = std::max( 10, clientSize.y );
m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
if( m_view )
{
@ -414,8 +416,10 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
delete m_gal;
m_gal = new_gal;
wxSize size = GetClientSize();
m_gal->ResizeScreen( size.GetX(), size.GetY() );
wxSize clientSize = GetClientSize();
clientSize.x = std::max( 10, clientSize.x );
clientSize.y = std::max( 10, clientSize.y );
m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
if( m_painter )
m_painter->SetGAL( m_gal );

View File

@ -210,6 +210,8 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
{
auto bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
auto screenSize = view->ToWorld( GetCanvas()->GetClientSize(), false );
screenSize.x = std::max( 10.0, screenSize.x );
screenSize.y = std::max( 10.0, screenSize.y );
double ratio = std::max( fabs( bbSize.x / screenSize.x ),
fabs( bbSize.y / screenSize.y ) );

View File

@ -1081,6 +1081,8 @@ void SELECTION_TOOL::zoomFitSelection()
auto view = getView();
VECTOR2D screenSize = view->ToWorld( m_frame->GetCanvas()->GetClientSize(), false );
screenSize.x = std::max( 10.0, screenSize.x );
screenSize.y = std::max( 10.0, screenSize.y );
if( selectionBox.GetWidth() != 0 || selectionBox.GetHeight() != 0 )
{