Prevent crash when a python script tries to use pcbnew too early.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15414

(cherry picked from commit b1b66f66f4)
This commit is contained in:
Alex Shvartzkop 2023-08-25 00:09:53 +03:00
parent 00226ae40a
commit 4497aaa3fa
3 changed files with 14 additions and 3 deletions

View File

@ -107,6 +107,7 @@
#include <footprint_viewer_frame.h>
#include <action_plugin.h>
#include <pcbnew_scripting_helpers.h>
#include "../scripting/python_scripting.h"
#include <wx/filedlg.h>
@ -477,6 +478,8 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
{
ScriptingOnDestructPcbEditFrame( this );
if( ADVANCED_CFG::GetCfg().m_ShowEventCounters )
{
// Stop the timer during destruction early to avoid potential event race conditions (that do happen on windows)

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.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
@ -77,6 +77,13 @@ void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPcbEditFrame )
}
void ScriptingOnDestructPcbEditFrame( PCB_EDIT_FRAME* aPcbEditFrame )
{
if( s_PcbEditFrame == aPcbEditFrame )
s_PcbEditFrame = nullptr;
}
BOARD* LoadBoard( wxString& aFileName )
{
if( aFileName.EndsWith( KiCadPcbFileExtension ) )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 NBEE Embedded Systems SL, Miguel Angel Ajo <miguelangel@ajo.es>
* Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2013-2023 KiCad Developers, see AUTHORS.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
@ -33,7 +33,8 @@
*/
#ifndef SWIG
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame );
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame );
void ScriptingOnDestructPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame );
#endif