-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArgumentException: The parameter is incorrect. pixelWidth, in SkiaSharp.Views.UWP SKXamlCanvas DoInvalidate() #582
Comments
I just opened the issue list to log this exact issue. Experienced this after updating from 1.60.0 to 1.60.2, I am using SkiaSharp within a Xamarin.Forms UWP application, in this instance to render a button used to navigate back, I don't get the issue in other scenarios, so it looks to me like it could be when destroying a control. Tried rolling back to 1.60.1 and the issue doesn't occur here. I also don't see an issue in iOS. |
I am still hitting the exception with IgnorePixelScaling enabled on the SKCanvasView, could it be a race condition where ActualWidth is changing between doing the check and creating the Bitmap? |
@DuncWatts The OnLoaded(), DoInvalidate(), and OnDpiChanged() functions are all identical between 1.60.0 and 1.60.2, so the issue isn't doesn't appear to related to the SkiaSharp version. What version of Xamarin.Forms are you using? We hadn't been getting this with 2.5.0, but we are now since we've updated to 3.1.0, however we also updated a number of other 3rd part packages so I didn't want to blame any one single package when it seemed like there was a simple fix possible in SkiaSharp. It could be a race issue, but in either case the fix I suggested should resolve it as the width and height are local variables whose values wouldn't change once assigned. It's also possible ActualWidth and ActualHeight are negative values for some reason, as the validation is only checking if they're zero. I haven't debugged into the SkiaSharp code yet, as the IgnorePixelScaling change fixed it for us. |
@jalbertSyncroTech I'm using Xamarin.Forms 3.1.0. All I say at the moment is I don't see any issues if I downgrade the SkiaSharp libraries to 1.60.0 or 1.60.1, only if I update to 1.60.2. |
Dpi is initialized in OnLoaded(). I found sometime OnSizeChanged is called before OnLoaded. So I think dpi should initialized in SKXamlCanvas.Initialize() directly. |
Thanks for reporting this, I'll try and make sure this gets into the next release. |
Make sure to initialize the DPI field. Fixes #582
Description
After a recent update to all of our third party nuget packages, we started getting this exception from SkiaSharp on UWP:
System.ArgumentException: The parameter is incorrect. pixelWidth
Call Stack:
SkiaSharp.Views.UWP.SKXamlCanvas.CreateBitmap(SkiaSharp.SKImageInfo info)
SkiaSharp.Views.UWP.SKXamlCanvas.DoInvalidate()
I tracked the cause down this check here:
SkiaSharp/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKXamlCanvas.cs
Line 94 in b8511b7
SkiaSharp is correctly checking that ActualWidth and ActualHeight are valid, but only before multiplying them by the dpi, so the exception is likely being caused by somebody else setting the dpi to zero or some other invalid value. As a test, I explicitly turned on IgnorePixelScaling in my control, and it successfully avoided the exception, proving that the bad value is coming from dpi.
A simple fix would be to move this check to after the "width" and "height" are calculated, and to validate those values instead of "ActualWidth" and "ActualHeight"
Basic Information
The text was updated successfully, but these errors were encountered: