From a2e61aee8925154ab24575c8aba58b3328fe654d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 11 Sep 2008 18:30:33 +0000 Subject: [PATCH] Fixed SD2-1450: Large amounts of output cause OutOfMemoryException git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3535 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../CompilerMessageView/MessageViewCategory.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/MessageViewCategory.cs b/src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/MessageViewCategory.cs index 3412e822c9..84c1af4d45 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/MessageViewCategory.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/MessageViewCategory.cs @@ -94,9 +94,21 @@ namespace ICSharpCode.SharpDevelop.Gui public void AppendText(string text) { + const int MaxTextSize = 50 * 1000 * 1000; // 50m chars = 100 MB + const string TruncatedText = "\r\n"; + lock (textBuilder) { - textBuilder.Append(text); - OnTextAppended(new TextEventArgs(text)); + if (textBuilder.Length + text.Length > MaxTextSize) { + int amountToCopy = MaxTextSize / 2 - text.Length; + if (amountToCopy <= 0) { + SetText(TruncatedText + text.Substring(text.Length - MaxTextSize / 2, MaxTextSize / 2)); + } else { + SetText(TruncatedText + textBuilder.ToString(textBuilder.Length - amountToCopy, amountToCopy) + text); + } + } else { + textBuilder.Append(text); + OnTextAppended(new TextEventArgs(text)); + } } }