0

I'm calling the RenderAsync() function of the GifRenderer class but it never returns. I get no error, it just never comes back. I'm starting with some byte arrays containing JPEG images. I create a collection of BufferImageSource objects for sources.

var sources = new List<IImageProvider>();
sources.Add(new BufferImageSource(frame.Data.AsBuffer(), ImageFormat.Jpeg));

I've even taken it down to only a single source buffer, but it still doesn't help. I've tried the RenderAsync() call with and without the ConfigureAwait() and that doesn't matter either. Any other things I can check?

using (var gifRenderer = new GifRenderer(sources))
{
  gifRenderer.Duration = 1000 / App.AppSettings.FramesPerSecond;
  gifRenderer.UseGlobalPalette = true;
  gifRenderer.Size = new Size(320, 240);
  var gifbuf = await gifRenderer.RenderAsync().AsTask().ConfigureAwait(false);
  // ... and so on
}
Arian Kulp
  • 831
  • 8
  • 31

1 Answers1

0

Alright, I figured it out. It wasn't specifically something with the Lumia library. It was a deadlock caused by a Dispatch Timer. I'm really not sure what that mattered since shouldn't be on the UI thread when it's asynchronous, but it works if I stop the Dispatch Timer, run the encode, then start it up again.

Arian Kulp
  • 831
  • 8
  • 31
  • Glad it worked out. May I ask what your image source objects were? E.g. if you pass a WriteableBitmap into a BitmapImageSource, there will be a dispatcher dependency there (the data in the WB can only be accessed from the UI thread). Even more insidiously, sometimes the WinRT class framework sometimes hands you a stream with a hidden dispatcher dependency. – CÅdahl Mar 09 '15 at 08:09
  • Glad it worked out. May I ask what your image source objects were? E.g. if you pass a WriteableBitmap into a BitmapImageSource, there will be a dispatcher dependency there (the data in the WB can only be accessed from the UI thread). Even more insidiously, sometimes the WinRT class framework sometimes hands you a stream with – CÅdahl Mar 09 '15 at 08:09
  • It was a collection of StreamImageSource objects. That is pretty insidious if it has a dispatcher dependency! – Arian Kulp Mar 09 '15 at 23:19
  • Yeah. You can sometimes determine if that's the case by following the call stack. I seem to recall that the streams provided by the file picker could have a UI thread dependency. – CÅdahl Mar 10 '15 at 06:42
  • To clarify slightly, StreamImageSource has no dependency and goes to some length to avoid them. – CÅdahl Mar 10 '15 at 06:43
  • thanks @CÅdahl. These are not chosen from the picker. Who knows what it was. I would have preferred to track it down, but it didn't require me to remove anything important so I was satisfied with just getting it to work! – Arian Kulp Mar 10 '15 at 20:09