From 427e5ec46149507c6f5e8cd743bd3b7aec61cac3 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Thu, 21 Sep 2017 12:37:12 -0400 Subject: [PATCH] Eeschema: fix crash when undo called during item edit. Add EDA_DRAW_FRAME::isBusy() method to test if the current item is being edited or a block operation is in progress. Ignore undo and redo commands when editor is busy. Fixes lp:1718656 https://bugs.launchpad.net/kicad/+bug/1718656 --- common/draw_frame.cpp | 13 ++++++++++++- eeschema/schematic_undo_redo.cpp | 6 +++--- include/draw_frame.h | 13 +++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index e09ec55bee..5a8bdc175a 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2008-2015 Wayne Stambaugh + * Copyright (C) 2008 Wayne Stambaugh * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -1370,3 +1370,14 @@ void EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, } } + +bool EDA_DRAW_FRAME::isBusy() const +{ + const BASE_SCREEN* screen = const_cast< BASE_SCREEN* >( GetScreen() ); + + if( !screen ) + return false; + + return ( screen->GetCurItem() && screen->GetCurItem()->GetFlags() ) + || ( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK ); +} diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index 1f7da2e205..ecc288bfb2 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -338,7 +338,7 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed void SCH_EDIT_FRAME::GetSchematicFromUndoList( wxCommandEvent& event ) { - if( GetScreen()->GetUndoCommandCount() <= 0 ) + if( GetScreen()->GetUndoCommandCount() <= 0 || isBusy() ) return; /* Get the old list */ @@ -361,7 +361,7 @@ void SCH_EDIT_FRAME::GetSchematicFromUndoList( wxCommandEvent& event ) void SCH_EDIT_FRAME::GetSchematicFromRedoList( wxCommandEvent& event ) { - if( GetScreen()->GetRedoCommandCount() == 0 ) + if( GetScreen()->GetRedoCommandCount() == 0 || isBusy() ) return; /* Get the old list */ diff --git a/include/draw_frame.h b/include/draw_frame.h index aa01690d03..135d01478f 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 2011-2017 Wayne Stambaugh + * Copyright (C) 2011 Wayne Stambaugh * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -154,11 +154,16 @@ protected: * cursor keys (i.e. cursor movement by keyboard) */ void GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, bool aSnapToGrid ); - /* Function RefreshCrosshair - * Move and refresh the crosshair after movement; also call the - * mouse capture function, if active. + /** + * Move and refresh the crosshair after movement and call the mouse capture function. */ void RefreshCrossHair( const wxPoint &aOldPos, const wxPoint &aEvtPos, wxDC* aDC ); + + /** + * @return true if an item edit or a block operation is in progress. + */ + bool isBusy() const; + public: EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,