This repository was archived by the owner on May 2, 2018. It is now read-only.
forked from sitdap/dynamic-image
-
Notifications
You must be signed in to change notification settings - Fork 33
Win32Exception is thrown when WPF runs out of internal resources #1
Copy link
Copy link
Open
Description
After an AppDomain has been up for a while, DynamicImage sometimes fails to generate an image because of an exception thrown by WPF:
System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully
at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
at System.Windows.Media.MediaContextNotificationWindow..ctor(MediaContext ownerMediaContext)
at System.Windows.Media.MediaContext..ctor(Dispatcher dispatcher)
at System.Windows.Media.MediaContext.From(Dispatcher dispatcher)
at System.Windows.Media.Imaging.WriteableBitmap.SubscribeToCommittingBatch()
at System.Windows.Media.Imaging.WriteableBitmap.Unlock()
at System.Windows.Media.Imaging.WriteableBitmap.InitFromBitmapSource(BitmapSource source)
at System.Windows.Media.Imaging.WriteableBitmap..ctor(BitmapSource source)
at SoundInTheory.DynamicImage.Util.FastBitmap..ctor(String filename, UriKind uriKind)
at SoundInTheory.DynamicImage.Sources.FileImageSource.GetBitmap()
at SoundInTheory.DynamicImage.Layers.ImageLayer.CreateImage()
at SoundInTheory.DynamicImage.Layer.Process()
at SoundInTheory.DynamicImage.Composition.CreateImage()
at SoundInTheory.DynamicImage.Composition.GenerateImage()
at SoundInTheory.DynamicImage.Caching.ImageUrlGenerator.GetImageUrl(Composition composition)
at SoundInTheory.DynamicImage.Fluent.CompositionBuilder.get_Url()
This looks to be related to the Dispatcher creating internal HwndWrapper objects. There is an SO question and answer here, which suggest that Dispatchers need to be cleaned up:
DynamicImage doesn't explicitly create threads, so there is nowhere obvious to plug that code in. Perhaps DynamicImage could maintain its own thread pool and do all image generation on one of those threads.