Bug 6401 - Crashing on CIContext() call
Summary: Crashing on CIContext() call
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-08-05 13:54 UTC by Ian
Modified: 2012-08-07 09:49 UTC (History)
2 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 Ian 2012-08-05 13:54:55 UTC
This function is used to recolor an image using Hue. The Xamarin docs use a method to get the image out, but that does not work on Retina. I use this code, suggested by Sebasstiaan on Stack Overflow. It crashes the system badly.

	public static UIImage ApplyColorScheme(UIImage originalImage)


			if (ColorScheme == General.ColorScheme.Blue || !UIDevice.CurrentDevice.CheckSystemVersion(5, 0))
				return originalImage;

			float hue = 0;

			switch (ColorScheme)
				case General.ColorScheme.Brown:
					hue = -173f;
				case General.ColorScheme.Cyan:
					hue = -35;
				case General.ColorScheme.Purple:
					hue = 74f;
				case General.ColorScheme.DarkRedBrown:
					hue = -180;

			var hueAdjust = new CIHueAdjust() {
				Image = CIImage.FromCGImage(originalImage.CGImage),
				Angle = hue * (float)Math.PI / 180f // angles to radians

			var output = hueAdjust.OutputImage;

			UIImage retVal = null;
			UIGraphics.BeginImageContextWithOptions(originalImage.Size, false, 0);
			var c = UIGraphics.GetCurrentContext ();
			var context = CIContext.FromContext(c);
			var cgimage = context.CreateCGImage(output, output.Extent);
			retVal = UIImage.FromImage(cgimage);


			return retVal;
Comment 2 Sebastien Pouliot 2012-08-07 09:05:57 UTC
Confirmed. Thanks for the sample code (I'll turn it into a new unit test :-)
Comment 3 Sebastien Pouliot 2012-08-07 09:49:55 UTC
The crash* is due to an endless recursion in FromContext. However this won't solve your original problem since the API that was exposed does not exists in iOS (it's OSX specific).

* fixed in maccore/master: ab15a52c3d7c1206eb041d56985cdb38b03aa70a