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 (show other bugs)
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)

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


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

Note You need to log in before you can comment on or make changes to this bug.