Skip to content

Commit

Permalink
QgsProcessingAlgorithmDialogBase: limit number of info messages to av…
Browse files Browse the repository at this point in the history
…oid blowing RAM (fixes #44202)
  • Loading branch information
rouault authored and github-actions[bot] committed Jul 21, 2021
1 parent cf2dcd7 commit ebeefc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Expand Up @@ -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() ) ) );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.h
Expand Up @@ -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 );
Expand Down

0 comments on commit ebeefc9

Please sign in to comment.