You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JIT exception thrown when creating animated gif on iOS #762
I have verified that I am running the latest version of ImageSharp
I have verified if the problem exist in both DEBUG and RELEASE mode
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 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.
@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.
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 ConstructPalette method BEFORE calling SaveAsGif(...):
var test = new OctreeFrameQuantizer<Rgba32>(new OctreeQuantizer(false));
test.AotGetPalette(); //stubbed out method that just calls empty ConstructPalette
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 few AotCompile methods 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.
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 :)
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 :)