WPF - 调用Measure时出错:没有足够的存储空间可用于处理此命令。 (HRESULT异常:0x80070008)

时间:2016-02-03 16:39:02

标签: c# wpf comexception

在WPF,单线程应用程序中,我将几个FixedPages添加到FixedDocument。每个FixedPage都包含许多其他对象,如Images和TextBlocks。

一切顺利,但过了一段时间(增加了大约300页),我创建了一个新的TextBlock,填充了一些属性,然后在将它添加到FixedPage之前,我调用Measure(width,height)来询问它想要的大小。在那次通话中,我得到以下例外:

System.Runtime.InteropServices.COMException was unhandled by user code
  ErrorCode=-2147024888
  HResult=-2147024888
  Message=Not enough storage is available to process this command. (Exception from HRESULT: 0x80070008)
  Source=mscorlib
  StackTrace:
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
       at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr)
       at MS.Internal.Text.TextInterface.FontFace.GetDesignGlyphMetrics(UInt16* pGlyphIndices, UInt32 glyphCount, GlyphMetrics* pGlyphMetrics)
       at System.Windows.Media.GlyphTypeface.GlyphMetrics(UInt16* pGlyphIndices, Int32 characterCount, GlyphMetrics* pGlyphMetrics, Double emSize, TextFormattingMode textFormattingMode, Boolean isSideways)
       at System.Windows.Media.GlyphTypeface.GetGlyphMetricsAndIndicesOptimized(UInt32* pCodepoints, Int32 characterCount, Double emSize, UInt16[] glyphIndices, GlyphMetrics[] glyphMetrics, TextFormattingMode textFormattingMode, Boolean isSideways)
       at System.Windows.Media.GlyphTypeface.GetGlyphMetricsOptimized(CharacterBufferRange characters, Double emSize, UInt16[] glyphIndices, GlyphMetrics[] glyphMetrics, TextFormattingMode textFormattingMode, Boolean isSideways)
       at System.Windows.Media.Typeface.CheckFastPathNominalGlyphs(CharacterBufferRange charBufferRange, Double emSize, Double scalingFactor, Double widthMax, Boolean keepAWord, Boolean numberSubstitution, CultureInfo cultureInfo, TextFormattingMode textFormattingMode, Boolean isSideways, Boolean breakOnTabs, Int32& stringLengthFit)
       at MS.Internal.TextFormatting.SimpleRun.CreateSimpleTextRun(CharacterBufferRange charBufferRange, TextRun textRun, TextFormatterImp formatter, Int32 widthLeft, Boolean emergencyWrap, Boolean breakOnTabs)
       at MS.Internal.TextFormatting.SimpleRun.Create(FormatSettings settings, CharacterBufferRange charString, TextRun textRun, Int32 cp, Int32 cpFirst, Int32 runLength, Int32 widthLeft, Int32 idealRunOffsetUnRounded)
       at MS.Internal.TextFormatting.SimpleTextLine.Create(FormatSettings settings, Int32 cpFirst, Int32 paragraphWidth)
       at MS.Internal.TextFormatting.TextFormatterImp.FormatLineInternal(TextSource textSource, Int32 firstCharIndex, Int32 lineLength, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache)
       at MS.Internal.TextFormatting.TextFormatterImp.FormatLine(TextSource textSource, Int32 firstCharIndex, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache)
       at MS.Internal.Text.Line.Format(Int32 dcp, Double width, TextParagraphProperties lineProperties, TextLineBreak textLineBreak, TextRunCache textRunCache, Boolean showParagraphEllipsis)
       at System.Windows.Controls.TextBlock.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)

其他线程似乎针对相同的错误,但它们的上下文看起来非常不同。 有什么建议可以解决这个问题吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

我在Microsoft Visual Studio论坛中找到了答案。它说:

  

TextInterface可能会导致内存泄漏   WPF团队已经回顾了这个问题,并在.NET 4.6中修复。

     

- Sachin发表[MSFT],2015年10月14日15:03

[参考资料]

https://social.msdn.microsoft.com/Forums/vstudio/en-US/350a8d21-f361-4983-9bc3-65c71a78cb52/comexception-this-command-is-not-enough-memory-available?forum=wpf

https://connect.microsoft.com/VisualStudio/feedback/details/1468770/exception-with-textinterface