Skip to content
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

Closed
jalbertSyncroTech opened this issue Jul 19, 2018 · 6 comments
Milestone

Comments

@jalbertSyncroTech
Copy link

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:

if (ActualWidth == 0 || ActualHeight == 0 ||

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

  • Version with issue: 1.60.2
  • IDE: Visual Studio 15.7.5
  • Platform Target Frameworks:
    • UWP: 10.0.16299
@DuncWatts
Copy link

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.

@DuncWatts
Copy link

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?

@jalbertSyncroTech
Copy link
Author

@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.

@DuncWatts
Copy link

@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.

@rhussell
Copy link

rhussell commented Jul 21, 2018

Dpi is initialized in OnLoaded(). I found sometime OnSizeChanged is called before OnLoaded. So I think dpi should initialized in SKXamlCanvas.Initialize() directly.

@mattleibow mattleibow added this to the v1.60.3 milestone Jul 22, 2018
@mattleibow
Copy link
Contributor

Thanks for reporting this, I'll try and make sure this gets into the next release.

mattleibow added a commit that referenced this issue Jul 24, 2018
Make sure to initialize the DPI field. Fixes #582
@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants