Bug 12291 - Flaw in implementation of MonoTouch.CoreGraphics.CGContext.SetLineDash
Summary: Flaw in implementation of MonoTouch.CoreGraphics.CGContext.SetLineDash
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2013-05-17 15:07 UTC by Joseph Remes
Modified: 2013-06-17 08:16 UTC (History)
3 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 Joseph Remes 2013-05-17 15:07:04 UTC
Apple's documentation for CGContextSetLineDash states that a NULL can be passed for the float[] to indicate that no dashing is desired, i.e., to turn it off. Your documentation is "not yet been entered".
Your wrapper method is insisting that the second argument be non-null. It crashes with an ArgumentNullException when I try to turn dashing off.
So is this a bug? Sure looks like it. If not, then how do I turn dashing off?

I am running the latest Studio 4.0.8
Comment 1 Sebastien Pouliot 2013-05-17 15:57:44 UTC
Looks like a bug, I'll review the documentation.
Comment 2 Joseph Remes 2013-05-17 16:38:54 UTC
Just FYI, I decided to try something that should not work and whose behavior is undefined. I sent in a zero-length array something like this

MyCGContext.SetLineDash(0, new float[] {}, 0);

And this worked. Huh!
Comment 3 Sebastien Pouliot 2013-05-17 17:16:32 UTC
There's nothing in [1] saying it should not work, or even be undefined. It's just a more complex way to say it's empty (which means no dashing) as the code is processing 0 element (so the array is never looked at).

Also since it's non-null it's not caught by Xamarin.iOS and won't throw the ArgumentNullException. That makes it a good workaround until a new, fixed, release is out.

[1] https://developer.apple.com/library/ios/#documentation/graphicsimaging/reference/CGContext/Reference/reference.html

Fixed in 81af7c0217dce290ed93470ff049bcccac61858d (master)
QA: Unit tests added
Comment 4 narayanp 2013-06-17 08:16:22 UTC
Today we have checked this issue with following builds:

X.S 4.0.7-1
Xamarin.iOS 6.3.6-76
Mono 3.0.11

And we have followed some steps:
1. Create iOS application.
2. Add following code to app delegate
CGContext context = new CGContext (IntPtr.Zero);
               context.SetLineDash (0, null, 0);
3. Add following code in appdelegate.cs file :
using MonoTouch.ObjCRuntime;
using System.Drawing;
using MonoTouch.CoreGraphics;
4. Build the project

Application build successfully.

Changing the status to Verified.