jfversluis / been-pwned

App that leverages the haveibeenpwned.com API by Troy Hunt. This app is available in the App Stores and is used in several of my talks as well as my book Xamarin.Forms Essentials.
MIT License
16 stars 3 forks source link

Support for SVG images #6

Closed sthewissen closed 7 years ago

sthewissen commented 7 years ago

Some of the data being returned by HIBP is in SVG. To support this we could implement FFImageLoading.Forms.Svg. Some of the plumbing for that is already in place but currently doesn't work as it should.

jfversluis commented 7 years ago

It seems for SVGs some underwater exception is thrown;

2017-08-13 16:12:14.936 BeenPwned.App.iOS[67874:9665157] Image loading failed: https://haveibeenpwned.com/Content/Images/PwnedLogos/126.svg;80x0 System.BadImageFormatException: Image is null

While the URL in this error results in a valid SVG image. So, for some reason that doesn't work yet.

Full error for one image:

2017-08-13 16:12:14.936 BeenPwned.App.iOS[67874:9665157] Image loading failed: https://haveibeenpwned.com/Content/Images/PwnedLogos/126.svg;80x0 System.BadImageFormatException: Image is null at FFImageLoading.Extensions.NSDataExtensions.ToImage (Foundation.NSData data, CoreGraphics.CGSize destSize, System.nfloat destScale, FFImageLoading.Extensions.NSDataExtensions+RCTResizeMode resizeMode, FFImageLoading.Work.ImageInformation imageinformation, System.Boolean allowUpscale) [0x00011] in <8aef96e4cc4241bd92f34513c6d0befb>:0 at FFImageLoading.Work.PlatformImageLoaderTask1+<GenerateImageAsync>d__3[TImageView].MoveNext () [0x0015e] in <8aef96e4cc4241bd92f34513c6d0befb>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at FFImageLoading.Work.ImageLoaderTask`2+d__109[TImageContainer,TImageView].MoveNext () [0x0047f] in :0

sthewissen commented 7 years ago

Currently were using basic FFImageLoading. In the Breaches.xaml page there is a declaration on top for ffimageloadingsvg as well. We should switch ffimageloading:CachedImage to ffimageloadingsvg:SvgCachedImage but that throws an exception for me.

jfversluis commented 7 years ago

Hm, seems implementation isn't complete yet on FFImageLoading's end.

The SvgCachedImage is only available in a pre-release version. In addition, there is no reference to the *.Svg.Forms package in code, only in XAML. That is not picked up by the iOS Linker and thus the library is optimized out.

Solving this quick and dirty can be done by a dummy line in code somewhere i.e: var foo = new FFImageLoading.Svg.Forms.SvgCachedImage(); in the AppdDelegate.cs.

However, doing all this, still results in the error I posted above.

jfversluis commented 7 years ago

Should be fixed in #13.

Some still give an error, like the Epic Games one. See error log below. I will contact them to see if they can confirm this.

2017-08-14 12:54:00.363 BeenPwned.App.iOS[94765:11107516] Image loading failed: https://haveibeenpwned.com/Content/Images/PwnedLogos/EpicGames.svg;(size=0x40,dip=True);160x0 System.IndexOutOfRangeException: Index was outside the bounds of the array. at FFImageLoading.Svg.Platform.SKSvg.ReadPolyPath (System.String pointsData, System.Boolean closePath) [0x00041] in <14cdd0605e654493833da0ef9f755a28>:0 at FFImageLoading.Svg.Platform.SKSvg.ReadElement (System.Xml.Linq.XElement e, SkiaSharp.SKCanvas canvas, SkiaSharp.SKPaint stroke, SkiaSharp.SKPaint fill) [0x00593] in <14cdd0605e654493833da0ef9f755a28>:0 at FFImageLoading.Svg.Platform.SKSvg.ReadElement (System.Xml.Linq.XElement e, SkiaSharp.SKCanvas canvas, SkiaSharp.SKPaint stroke, SkiaSharp.SKPaint fill) [0x00641] in <14cdd0605e654493833da0ef9f755a28>:0 at FFImageLoading.Svg.Platform.SKSvg.ReadElement (System.Xml.Linq.XElement e, SkiaSharp.SKCanvas canvas, SkiaSharp.SKPaint stroke, SkiaSharp.SKPaint fill) [0x00811] in <14cdd0605e654493833da0ef9f755a28>:0 at FFImageLoading.Svg.Platform.SKSvg.ReadElement (System.Xml.Linq.XElement e, SkiaSharp.SKCanvas canvas) [0x0000b] in <14cdd0605e654493833da0ef9f755a28>:0 at FFImageLoading.Svg.Platform.SKSvg.LoadElements (System.Collections.Generic.IEnumerable`1[T] elements, SkiaSharp.SKCanvas canvas) [0x00010] in <14cdd0605e654493833da0ef9f755a28>:0 at FFImageLoading.Svg.Platform.SKSvg.Load (System.Xml.Linq.XDocument xdoc) [0x00407] in <14cdd0605e654493833da0ef9f755a28>:0 at FFImageLoading.Svg.Platform.SKSvg.Load (System.IO.Stream stream) [0x00007] in <14cdd0605e654493833da0ef9f755a28>:0 at FFImageLoading.Svg.Platform.SvgDataResolver+d__19.MoveNext () [0x001c9] in <14cdd0605e654493833da0ef9f755a28>:0

jfversluis commented 7 years ago

Found and fixed the problem!

Hopefully this will get merged soon and should be fixed then when we update the packages.