none
FontCacheFullException / OutOfMemoryException while running an WPF animation

    General discussion

  • Hi,

    I am developing an application that contains several animations and one of the animations is causing FontCacheFullExceptions
    when I run the animation repeatedly.

    The animation resizes a few grids (via RenderTransform), each containing one or two labels.

    Here is the stack-trace as I see it in Visual Studio right when the FontCacheFullException occurs:

         PresentationCore.dll!MS.Internal.FontCache.ElementCacher.Alloc(int size) + 0xd9 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.BaseGlyphElement.Allocate(int size) + 0x10 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.BaseGlyphElement.AllocateNoThrow(int size) + 0x21 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.GlyphBitmapElement.AllocateBitmap(int size) + 0xb Bytes   
         PresentationCore.dll!MS.Internal.TrueTypeRasterizer.GetBitmap(
            MS.Internal.FontRasterization.GetMemoryCallback getMemoryCallback, System.IntPtr currentPointer,
            int currentSize, out MS.Internal.FontRasterization.GlyphBitmap glyphBitmap = {MS.Internal.FontRasterization.GlyphBitmap},
            out MS.Internal.FontRasterization.GlyphMetrics glyphMetrics) + 0x328 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.GlyphBitmapElement.AddGlyph(ushort glyphIndex = 67) + 0x1b6 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.FontCacheAccessor.GetGlyphs(
            MS.Internal.FontCache.BaseGlyphElement element = {MS.Internal.FontCache.GlyphBitmapElement},
            System.Collections.Generic.IList<ushort> glyphIndices = {MS.Internal.PartialList<ushort>},
            void*[] glyphsArray = {void*[8]}) + 0x335 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.FontCacheAccessor.GetBitmaps(string fontFileName, int faceIndex, int scaleX,
            int scaleY,  ushort pointSize, ushort renderingMode, ushort renderingFlags, int glyphCount, ushort[] glyphIndices,
            void*[] glyphBitmaps) + 0xd7 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.FontCacheAccessor.CreateGlyphBitmapsHelper(
            System.IntPtr nativeGlyphCache = 66191960,
            MS.Internal.FontCache.FontCacheAccessor.FontFaceID faceId = {MS.Internal.FontCache.FontCacheAccessor.FontFaceID},
            ushort[] glyphIndices = {ushort[8]}, uint faceHandle = 1462) + 0x82 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.FontCacheAccessor.CreateGlyphsAtRenderTime(System.IntPtr nativeObject,
            System.IntPtr request, ushort isGeometryRequest) + 0xa0 Bytes   
         PresentationCore.dll!MS.Internal.FontCache.FontCacheAccessor.CreateGlyphsCallback(System.IntPtr nativeObject,
             System.IntPtr request, ushort isGeometryRequest) + 0x42 Bytes

    as a result of the FontCacheFullException an OutOfMemoryException gets thrown (same stack trace, but starting at TrueTypeRasterizer.GetBitmap())

    The exception doesn't crash the application, but the animation stagnates and the user experience is terrible.

    What can I do to prevent these memory problems?
    • Changed type Marco Zhou Wednesday, June 18, 2008 10:20 AM OP doesn't revert back
    Wednesday, June 11, 2008 4:02 PM

All replies

  • Could you please provide a small, complete and ready-to-run example to demonstrate the issue you are encountering?


    Thanks

    Monday, June 16, 2008 5:07 AM
  • We are changing the issue type to “Comment” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by clicking the "Options" link at the top of your post, and selecting "Change Type" menu item from the pop menu. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

     

    Thank you!

    Wednesday, June 18, 2008 10:19 AM
  • Hi,

    I am running into a similar problem.  Here is an example app:

    Window.xaml

    <Window x:Class="FontCacheException.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1">
        <StackPanel x:Name="stackPanel">
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
            <TextBlock>
                Hello
            </TextBlock>
        </StackPanel>
    </Window>

    Window1.xaml.cs

    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media.Animation;
    namespace FontCacheException
    {
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();

                DoubleAnimation animation = new DoubleAnimation(10.0, 40.0, new Duration(TimeSpan.FromSeconds(3.0)));
                animation.AutoReverse = true;
                animation.RepeatBehavior = RepeatBehavior.Forever;

                foreach (UIElement element in stackPanel.Children)
                {
                    element.BeginAnimation(TextBlock.FontSizeProperty, animation);
                }
            }
        }
    }

    If you let this app run, it will eventually throw a FontCacheFullException.

    Thanks for your help,
    Gabe
    Monday, July 28, 2008 3:04 PM
  • I am facing a similar issue in my application.

    Its a simple app using a Text Block and a Rectangle and VisualBrush to clone and blur the text block.
    A resize animation is applied on the rectangle to give the effect a image zoom.

    I have run into the same problem wherein the FontCache size goes on increasing and finally crosses over the MaxCacheSize limit and the initially the FontCacheFullException is thrown and caught. Later on the OOM exception gets thrown and my app crashes.

    I have tried turning off the PresentationFontCache service, it still crashes.

    I am on v3.5 SP1.

    Is this a bug in WPF or there is something we ought to do but i am missing.

    Thanks,
    Samit
    • Edited by Samit Sasan Wednesday, December 03, 2008 8:08 AM copy editing
    Wednesday, December 03, 2008 8:07 AM
  • We're running into this issue too.  Is anything being done about it?

    We are developing our SyntaxEditor for WPF product (a syntax-highlighting code editor control) and we have a mouse wheel zoom feature where it animates the text size up and down when you hold ctrl and rotate the mouse wheel.  We haven't run into this exception ourselves yet, however one of our alpha testers continuously does when he zooms in and out using this feature (the zooming uses smooth animation).

    For a screenshot and better description of the feature that is causing this bug in the framework to show up, see this post:

    http://blog.actiprosoftware.com/post/SyntaxEditor-for-WPF-ndash3b-Mouse-wheel-zooming---Part-2.aspx


    actiprosoftware.com - WPF ribbon, docking/mdi, navbar, explorerbar, breadcrumb, gauge, bar code, wizard controls & much more
    Friday, January 30, 2009 12:15 PM
  • Hi,
        I am getting a similar problem from a UI anchored within a Viewbox if the user resizes the application window with the mouse for approximately 30 seconds. The UI has a number of labels and other text elements on it.

    Any sign of a fix or suggestions as to what not to do?
    Tuesday, February 10, 2009 4:35 AM