Fix crash after calling EDIT_TOOL::pickCopyReferencePoint()

An instance of STATUS_TEXT_POPUP was created on the stack.
But it crashes pcbnew when closing the current main frame,
perhaps due to stack switching in coroutines.
It is now created on the heap.
This commit is contained in:
jean-pierre charras 2020-01-31 16:08:18 +01:00
parent bb06e672e7
commit f6881ce3de
1 changed files with 12 additions and 9 deletions

View File

@ -1326,33 +1326,36 @@ int EDIT_TOOL::EditFpInFpEditor( const TOOL_EVENT& aEvent )
bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aReferencePoint )
{
std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
STATUS_TEXT_POPUP statusPopup( frame() );
// Do not create statusPopup on the stack:
// it crashes pcbnew when closing the current main frame
// (perhaps due to stack switching in coroutines)
std::unique_ptr<STATUS_TEXT_POPUP> statusPopup( new STATUS_TEXT_POPUP( frame() ) );
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
OPT<VECTOR2I> pickedPoint;
bool done = false;
statusPopup.SetText( _( "Select reference point for the copy..." ) );
statusPopup->SetText( _( "Select reference point for the copy..." ) );
picker->SetClickHandler(
[&]( const VECTOR2D& aPoint ) -> bool
{
pickedPoint = aPoint;
statusPopup.SetText( _( "Selection copied." ) );
statusPopup.Expire( 800 );
statusPopup->SetText( _( "Selection copied." ) );
statusPopup->Expire( 800 );
return false; // we don't need any more points
} );
picker->SetMotionHandler(
[&] ( const VECTOR2D& aPos )
{
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
statusPopup->Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
} );
picker->SetCancelHandler(
[&]()
{
statusPopup.SetText( _( "Copy cancelled." ) );
statusPopup.Expire( 800 );
statusPopup->SetText( _( "Copy cancelled." ) );
statusPopup->Expire( 800 );
} );
picker->SetFinalizeHandler(
@ -1361,8 +1364,8 @@ bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aReferencePoint )
done = true;
} );
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
statusPopup.Popup();
statusPopup->Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
statusPopup->Popup();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );