Bug 40230 - CGPath.FromRoundedRect does neither contain needed parameter checks nor exception handling.
Summary: CGPath.FromRoundedRect does neither contain needed parameter checks nor excep...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.6 (iOS 9.3)
Hardware: PC Windows
: Normal enhancement
Target Milestone: (C9)
Assignee: Sebastien Pouliot
Depends on:
Reported: 2016-04-08 10:30 UTC by Evgeniy Zverev
Modified: 2016-10-12 12:34 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Evgeniy Zverev 2016-04-08 10:30:07 UTC
A piece of code like that crashes iOS app, exception handling (try/catch) does not help.

CGRect clsRect = new CGRect(1, 1, 25, 25);
CGSize clsRadius = new CGSize(13.5, 13.5);
CGPath clsPath = CGPath.FromRoundedRect(clsRect, clsRadius.Width, clsRadius.Height);

In my xamarin.forms app the code is inside a custom renderer. As a workaround I created a wrapper with correct parameter checks and an exception for wrong parameter values.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2016-04-08 15:40:15 UTC
This is iOS itself who is aborting:

Assertion failed: (corner_width >= 0 && 2 * corner_width <= CGRectGetWidth(rect)), function CGPathCreateWithRoundedRect, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Quartz2D_Sim/Quartz2D-1033.1/CoreGraphics/Paths/CGPath.cc, line 189.

We should probably add bounds checks ourselves and raise normal exceptions instead.
Comment 2 Evgeniy Zverev 2016-04-08 17:36:13 UTC
Is it normal for iOS to crash like that with an assertion? Do apple guys consider that a bug?
Comment 3 Sebastien Pouliot 2016-04-08 17:52:43 UTC
Unlike .NET Apple API are not very consistent in their error handling*. Some returns `nil` (if applicable), some will write to `stderr` (and do nothing, which can be confusing) and some will assert (effectively killing the running app).

In general we don't duplicate Apple argument checks. Code duplication slows down execution and takes more space. However if we can avoid a crash, like this case, then we will add the code to throw an ArgumentException.

* We often file bugs on rdar [1] and it's being said (not by Apple) that duplicates (of the same bugs) often set their priority. Still I encourage you to file such issues with us _and_ Apple for the benefits of all iOS developers :-)

[1] http://bugreport.apple.com
Comment 4 Evgeniy Zverev 2016-04-08 17:56:14 UTC
Actually I did that already i.e. posted a bug to apple, was curious what to expect from that. Thanks for clarification.
Comment 5 Sebastien Pouliot 2016-10-07 20:02:44 UTC
PR (master) https://github.com/xamarin/xamarin-macios/pull/966