Pcbnew: fix crash on Linux (when opening Edit Spice model in component properties)

It happens when the spice library model shown in dialog is a large file.
Looks like the wxTextCtrl used to displays the library content
creates the crash ( GKT bug?) for large texts.

The fix is to replace this wxTextCtrlt by a wxStyledTextCtrl.
It has advantages (does not crash... and much faster display) and
inconvenients (cannot disable editing).

Fixes: lp:1853161
https://bugs.launchpad.net/kicad/+bug/1853161
This commit is contained in:
jean-pierre charras 2019-11-21 11:28:43 +01:00
parent 3be1862b0f
commit e6346c7408
4 changed files with 270 additions and 4522 deletions

View File

@ -677,12 +677,14 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath )
file.Open( filePath.GetFullPath() );
int line_nr = 0;
// Stores the libray content. It will be displayed after reading the full library
wxString fullText;
// Process the file, looking for components
while( !file.Eof() )
{
const wxString& line = line_nr == 0 ? file.GetFirstLine() : file.GetNextLine();
m_libraryContents->AppendText( line );
m_libraryContents->AppendText( "\n" );
fullText << line << '\n';
wxStringTokenizer tokenizer( line );
@ -729,6 +731,9 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath )
++line_nr;
}
// display the full library content:
m_libraryContents->AppendText( fullText );
wxArrayString modelsList;
// Refresh the model name combobox values

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 11 2018)
// C++ code generated with wxFormBuilder (version Jul 10 2019)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -240,10 +240,37 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i
bSizer6->Add( fgSizer3, 0, wxEXPAND, 5 );
m_libraryContents = new wxTextCtrl( m_model, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_DONTWRAP|wxTE_MULTILINE|wxTE_READONLY );
m_libraryContents->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) );
bSizer6->Add( m_libraryContents, 1, wxALL|wxEXPAND, 5 );
m_libraryContents = new wxStyledTextCtrl( m_model, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
m_libraryContents->SetUseTabs( false );
m_libraryContents->SetTabWidth( 4 );
m_libraryContents->SetIndent( 4 );
m_libraryContents->SetTabIndents( true );
m_libraryContents->SetBackSpaceUnIndents( true );
m_libraryContents->SetViewEOL( false );
m_libraryContents->SetViewWhiteSpace( false );
m_libraryContents->SetMarginWidth( 2, 0 );
m_libraryContents->SetIndentationGuides( false );
m_libraryContents->SetMarginWidth( 1, 0 );
m_libraryContents->SetMarginType( 0, wxSTC_MARGIN_NUMBER );
m_libraryContents->SetMarginWidth( 0, m_libraryContents->TextWidth( wxSTC_STYLE_LINENUMBER, wxT("_99999") ) );
m_libraryContents->MarkerDefine( wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS );
m_libraryContents->MarkerSetBackground( wxSTC_MARKNUM_FOLDER, wxColour( wxT("BLACK") ) );
m_libraryContents->MarkerSetForeground( wxSTC_MARKNUM_FOLDER, wxColour( wxT("WHITE") ) );
m_libraryContents->MarkerDefine( wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS );
m_libraryContents->MarkerSetBackground( wxSTC_MARKNUM_FOLDEROPEN, wxColour( wxT("BLACK") ) );
m_libraryContents->MarkerSetForeground( wxSTC_MARKNUM_FOLDEROPEN, wxColour( wxT("WHITE") ) );
m_libraryContents->MarkerDefine( wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_EMPTY );
m_libraryContents->MarkerDefine( wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUS );
m_libraryContents->MarkerSetBackground( wxSTC_MARKNUM_FOLDEREND, wxColour( wxT("BLACK") ) );
m_libraryContents->MarkerSetForeground( wxSTC_MARKNUM_FOLDEREND, wxColour( wxT("WHITE") ) );
m_libraryContents->MarkerDefine( wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUS );
m_libraryContents->MarkerSetBackground( wxSTC_MARKNUM_FOLDEROPENMID, wxColour( wxT("BLACK") ) );
m_libraryContents->MarkerSetForeground( wxSTC_MARKNUM_FOLDEROPENMID, wxColour( wxT("WHITE") ) );
m_libraryContents->MarkerDefine( wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_EMPTY );
m_libraryContents->MarkerDefine( wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_EMPTY );
m_libraryContents->SetSelBackground( true, wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
m_libraryContents->SetSelForeground( true, wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
bSizer6->Add( m_libraryContents, 1, wxEXPAND | wxALL, 5 );
m_model->SetSizer( bSizer6 );
@ -698,7 +725,6 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i
this->SetSizer( bSizer1 );
this->Layout();
bSizer1->Fit( this );
this->Centre( wxBOTH );

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,11 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 11 2018)
// C++ code generated with wxFormBuilder (version Jul 10 2019)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_SPICE_MODEL_BASE_H__
#define __DIALOG_SPICE_MODEL_BASE_H__
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
@ -27,6 +26,7 @@
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/stc/stc.h>
#include <wx/statbox.h>
#include <wx/listctrl.h>
#include <wx/notebook.h>
@ -91,7 +91,7 @@ class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM
wxComboBox* m_modelName;
wxStaticText* m_staticText4;
wxComboBox* m_modelType;
wxTextCtrl* m_libraryContents;
wxStyledTextCtrl* m_libraryContents;
wxPanel* m_power;
wxStaticText* m_staticText10;
wxTextCtrl* m_genDc;
@ -195,9 +195,8 @@ class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM
public:
DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Spice Model Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Spice Model Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 494,604 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_SPICE_MODEL_BASE();
};
#endif //__DIALOG_SPICE_MODEL_BASE_H__