Skip to content
Permalink
Browse files
QgsProcessingAlgorithmDialogBase: limit number of info messages to av…
…oid blowing RAM (fixes #44202)
  • Loading branch information
rouault authored and github-actions committed Jul 21, 2021
1 parent cf2dcd7 commit ebeefc954502e2f9a4cbd21ffe97a8ab19564847
@@ -677,9 +677,17 @@ QString QgsProcessingAlgorithmDialogBase::formatStringForLog( const QString &str

void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isError, bool escapeHtml, bool isWarning )
{
constexpr int MESSAGE_COUNT_LIMIT = 10000;
// Avoid logging too many messages, which might blow memory.
if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
return;
++mMessageLoggedCount;

// note -- we have to wrap the message in a span block, or QTextEdit::append sometimes gets confused
// and varies between treating it as a HTML string or a plain text string! (see https://github.com/qgis/QGIS/issues/37934)
if ( isError || isWarning )
if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).arg( tr( "Message log truncated" ) ) );
else if ( isError || isWarning )
txtLog->append( QStringLiteral( "<span style=\"color:%1\">%2</span>" ).arg( isError ? QStringLiteral( "red" ) : QStringLiteral( "#b85a20" ), escapeHtml ? formatStringForLog( message.toHtmlEscaped() ) : formatStringForLog( message ) ) );
else if ( escapeHtml )
txtLog->append( QStringLiteral( "<span>%1</span" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
@@ -415,6 +415,8 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsPr

bool mHelpCollapsed = false;

int mMessageLoggedCount = 0;

QgsProcessingContext::LogLevel mLogLevel = QgsProcessingContext::DefaultLevel;

QString formatHelp( QgsProcessingAlgorithm *algorithm );

0 comments on commit ebeefc9

Please sign in to comment.