Bug 5088 - No way to check if creation of a CGBitmapContext failed
Summary: No way to check if creation of a CGBitmapContext failed
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-05-15 09:30 UTC by René Ruppert
Modified: 2012-05-15 10:28 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 René Ruppert 2012-05-15 09:30:19 UTC
In ObjectiveC I would use CGBitmapContextCreate() to get a new bitmap context. If creation fails (because there isn't enough memory for instance), NIL will be returned.

In Monotouch however, I have to use new CGBitmapContext() - there is no static method to create the context.

If creation fails in Monotouch, I will see

<Error>: CGBitmapContextInfoCreate: unable to allocate 2851360 bytes for bitmap data

in the logs but there is no way to react on it, construction of my object will just fail and the app crash.

Comment 1 Sebastien Pouliot 2012-05-15 10:07:32 UTC
from my stackoverflow answer [1]:

> If an invalid object (like null) is returned then the C# instance will have an Handle equals to IntPtr.Zero. This is true for any ObjC object, since init can return nil and a .NET constructor cannot return null.

[1] http://stackoverflow.com/a/10602489/220643
Comment 2 René Ruppert 2012-05-15 10:10:37 UTC
Excellent! Thanks!
Comment 3 Sebastien Pouliot 2012-05-15 10:28:15 UTC
I assume it's resolved then :)
re-open if I'm wrong (w/additional data)