Repository navigation
Description
Prerequisites
- I have written a descriptive issue title
- I have verified that I am running the latest version of ImageSharp
- I have verified if the problem exist in both
DEBUGandRELEASEmode - I have searched open and closed issues to ensure it has not already been reported
Description
When creating animated gifs on iOS devices, a JIT exception is thrown by the quantizer and the operation fails:
Attempting to JIT compile method 'SixLabors.ImageSharp.Processing.Processors.Quantization.OctreeFrameQuantizer`1/Octree/OctreeNode<SixLabors.ImageSharp.PixelFormats.Rgba32>:ConstructPalette (SixLabors.ImageSharp.PixelFormats.Rgba32[],int&)' while running in aot-only mode. See https://developer.xamarin.com/guides/ios/advanced_topics/limitations/ for more information.
The WuQuantizer throws a similar exception:
Attempting to JIT compile method 'SixLabors.ImageSharp.Processing.Processors.Quantization.WuFrameQuantizer`1<SixLabors.ImageSharp.PixelFormats.Rgba32>:GetPalette ()' while running in aot-only mode. See https://developer.xamarin.com/guides/ios/advanced_topics/limitations/ for more information.
The Xamarin link in the exception message mentions decorating the method with the UnmanagedFunctionPointerAttribute to fix the problem.
https://docs.microsoft.com/en-us/xamarin/ios/internals/limitations#no-dynamic-code-generation
Steps to Reproduce
I see this error everytime I try to create an animated gif on iOS.
I have a sample project here that demonstrates the problem:
https://github.com/dmanning23/MonogameScreenToolsExample
https://github.com/dmanning23/MonogameScreenTools
System Configuration
I'm seeing this issue on an iPhone 5S running iOS 12.0.1
- ImageSharp version: I am using the "dev" package from the ImageSharp nightly myget stream.
Activity
JimBobSquarePants commentedon Oct 30, 2018
@dmanning23 Thanks for the info and initial research
https://developer.xamarin.com/guides/ios/advanced_topics/limitations/
I have no experience with mobile development so hopefully someone reads this and has a clue what this actually means.
dmanning23 commentedon Oct 30, 2018
The guidelines mention an attribute that can be used to decorate the problem method. There are a few examples out there showing how to use it, I was going to fart around with it later this afternoon and see if I can get it working.
antonfirsov commentedon Oct 30, 2018
It seems to me that you are facing this specific limiatation.
@dmanning23 can you try a little experiment for us?
PixelOperations<Bgra32> operations = PixelOperations<Bgra32>.InstanceNotes:
Span<T>you can use the extension methodarray.AsSpan()Span<T>is implictily convertible toReadOnlySpan<T>)antonfirsov commentedon Oct 30, 2018
@dmanning23 as @JimBobSquarePants mentioned, there are no Xamarin devs in the core team, but I have a few more ideas to try, if it's possible for you to use a manually built version of ImageSharp.
dmanning23 commentedon Nov 2, 2018
Ok, I've made a bit of headway on this issue... If I explicitly build one of those objects (with the correct generic type) and call the
ConstructPalettemethod BEFORE callingSaveAsGif(...):Now when it hits that bit of code when calling
SaveAsGif<Rgba32>, it has already seen it ahead-of-time and doesn't need to spin up the JIT compiler. I can't think of a very elegant way to fix it though... The easiest thing I can think of is adding a fewAotCompilemethods that are similar to above, that the user can call at init on iOS.kinda gross, but it would work :) I'll put together a PR so yall can give me your thoughts.
dlemstra commentedon Nov 5, 2018
Have you tried any of the workarounds mentioned here: https://support.frozenmountain.com/hc/en-us/articles/115000767214-Known-Issue-with-Xamarin-iOS-10-10.
dmanning23 commentedon Nov 5, 2018
Looks like those workarounds are if this issue pops up from calling p/invoke, I don't think any of those would work because the error here is due to the heavy generic usage in ImageSharp. I have a PR open that adds a few methods that can be used to pre-seed the AoT compiler on iOS. I've been able to generate animated gifs on iOS using this technique :)