Repository navigation
JIT exception thrown when creating animated gif on iOS #762
Description
Activity
@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.
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.
It seems to me that you are facing this specific limiatation.
@dmanning23 can you try a little experiment for us?
- Create an application referencing the dev/MyGet version of ImageSharp and System.Memory, that does nothing else but
PixelOperations<Bgra32> operations = PixelOperations<Bgra32>.Instance- Invoke something like this method on the instance created in (2.), using reflection.
Notes:- reflection is needed because the method is internal
- to get an instance to
Span<T>you can use the extension methodarray.AsSpan() Span<T>is implictily convertible toReadOnlySpan<T>)
Reacted by James Jackson-South@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.
Reacted by James Jackson-SouthOk, 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(...):var test = new OctreeFrameQuantizer<Rgba32>(new OctreeQuantizer(false)); test.AotGetPalette(); //stubbed out method that just calls empty ConstructPaletteNow 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.Reacted by Anton Firszov and James Jackson-SouthHave you tried any of the workarounds mentioned here: https://support.frozenmountain.com/hc/en-us/articles/115000767214-Known-Issue-with-Xamarin-iOS-10-10.
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 :)
Reacted by Anton Firszov and James Jackson-South
Prerequisites
DEBUGandRELEASEmodeDescription
When creating animated gifs on iOS devices, a JIT exception is thrown by the quantizer and the operation fails:
The WuQuantizer throws a similar exception:
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