Gerbview: fix a maximum number (50) of Error messages in report list.

Having a lot of errors can happen when trying to open a non gerber files
(this is easy when loading a zip archive).
With a *lot* of errors (if a large .step file is found) Gerbview can hang.

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

(cherry picked from commit d5cf54197468a825ba8cf09b46d228d9f425f7d1)
This commit is contained in:
jean-pierre charras 2025-04-28 17:39:53 +02:00
parent fb92923f82
commit 6c30e4f90b
3 changed files with 16 additions and 5 deletions

View File

@ -112,6 +112,20 @@ GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE()
} }
void GERBER_FILE_IMAGE::AddMessageToList( const wxString& aMessage )
{
/* Add a message to the message list, but only if there are less than max_messages
* to avoid very long list (can happens if trying to read a non gerber file)
*/
const int max_messages = 50; // Arbitrary but reasonable value.
if( m_messagesList.size() < max_messages )
m_messagesList.Add( aMessage );
else if( m_messagesList.size() == max_messages )
m_messagesList.Add( _( "Too many messages, some are skipped" ) );
}
void GERBER_FILE_IMAGE::SetDrawOffetAndRotation( VECTOR2D aOffsetMM, EDA_ANGLE aRotation ) void GERBER_FILE_IMAGE::SetDrawOffetAndRotation( VECTOR2D aOffsetMM, EDA_ANGLE aRotation )
{ {
m_DisplayOffset.x = KiROUND( aOffsetMM.x * gerbIUScale.IU_PER_MM ); m_DisplayOffset.x = KiROUND( aOffsetMM.x * gerbIUScale.IU_PER_MM );

View File

@ -212,10 +212,7 @@ public:
/** /**
* Add a message to the message list * Add a message to the message list
*/ */
void AddMessageToList( const wxString& aMessage ) void AddMessageToList( const wxString& aMessage );
{
m_messagesList.Add( aMessage );
}
/** /**
* Return the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm). * Return the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm).

View File

@ -323,7 +323,7 @@ bool GERBER_FILE_IMAGE::LoadGerberFile( const wxString& aFullFileName )
break; break;
default: default:
msg.Printf( wxT( "Unexpected char 0x%2.2X" ), *text ); msg.Printf( wxT( "Unexpected char 0x%2.2X (%c)" ), *text, *text );
AddMessageToList( msg ); AddMessageToList( msg );
text++; text++;
break; break;