diff --git a/common/single_top.cpp b/common/single_top.cpp index dba849d9f8..0b53fe3250 100644 --- a/common/single_top.cpp +++ b/common/single_top.cpp @@ -143,8 +143,10 @@ struct APP_SINGLE_TOP : public wxApp int OnExit() // overload wxApp virtual { + // Fixes segfault when wxPython scripting is enabled. +#if defined( KICAD_SCRIPTING_WXPYTHON ) Pgm().OnPgmExit(); - +#endif return wxApp::OnExit(); } @@ -171,6 +173,11 @@ struct APP_SINGLE_TOP : public wxApp wxLogError( wxT( "Unhandled exception of unknown type" ) ); } + // Works properly when wxPython scripting is disabled. +#if !defined( KICAD_SCRIPTING_WXPYTHON ) + Pgm().OnPgmExit(); +#endif + return ret; } @@ -281,8 +288,9 @@ bool PGM_SINGLE_TOP::OnPgmInit( wxApp* aWxApp ) // We've already initialized things at this point, but wx won't call OnExit if // we fail out. Call our own cleanup routine here to ensure the relevant resources // are freed at the right time (if they aren't, segfaults will occur). +#if defined( KICAD_SCRIPTING_WXPYTHON ) OnPgmExit(); - +#endif // Fail the process startup if the file could not be opened, // although this is an optional choice, one that can be reversed // also in the KIFACE specific OpenProjectFiles() return value. diff --git a/scripting/python_scripting.cpp b/scripting/python_scripting.cpp index 0f8072e6ff..827ab304bc 100644 --- a/scripting/python_scripting.cpp +++ b/scripting/python_scripting.cpp @@ -145,7 +145,16 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath ) // are different versions of wxPython installed this can lead to select wrong wxPython // version being selected. snprintf( cmd, sizeof(cmd), "import wxversion; wxversion.select('%s')", WXPYTHON_VERSION ); - PyRun_SimpleString( cmd ); + + int retv = PyRun_SimpleString( cmd ); + + if( retv != 0 ) + { + wxLogError( wxT( "Python error %d occurred running string `%s`" ), retv, cmd ); + PyErr_Print(); + Py_Finalize(); + return false; + } // Load the wxPython core API. Imports the wx._core_ module and sets a // local pointer to a function table located there. The pointer is used