Bug 28243 - NSBitmapImageRep should check for null initWithFocusedViewRect and throw with more detailed error message
Summary: NSBitmapImageRep should check for null initWithFocusedViewRect and throw with...
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) (show other bugs)
Version: 1.12.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: master
Assignee: Bugzilla
Depends on:
Reported: 2015-03-20 10:55 UTC by Chris Hamons
Modified: 2016-09-26 21:59 UTC (History)
4 users (show)

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

Test Project (347.09 KB, application/zip)
2016-05-03 20:57 UTC, Jon Goldberger [MSFT]

Comment 1 Jon Goldberger [MSFT] 2016-05-03 20:38:44 UTC
We have a customer reporting this issue. 

Simply doing 
>NSBitmapImageRep newRep = new NSBitmapImageRep (new CGRect (0, 0, 100, 100));

causes this issue.
Comment 3 Jon Goldberger [MSFT] 2016-05-03 20:53:27 UTC
Additional note:

If I set
>ObjCRuntime.Class.ThrowOnInitFailure = false;

then the NSBitmapImageRep gets initialized and is not null. i.e. doing:

>ObjCRuntime.Class.ThrowOnInitFailure = false;
>NSBitmapImageRep newRep = new NSBitmapImageRep (this.View.Frame);

and then inspecting newRep after this call the object is not null:

So curious as to why the init is failing without calling setting the ThrowOnInitFailure to false.
Comment 4 Jon Goldberger [MSFT] 2016-05-03 20:57:54 UTC
Created attachment 15896 [details]
Test Project

This test project does set the 
>ObjCRuntime.Class.ThrowOnInitFailure = false;

so the NSBitmapImageRep does get created and is not null and the app does not crash.
Comment 5 Jon Goldberger [MSFT] 2016-05-04 18:09:31 UTC
Update from customer hitting this issue:

"K, so the error no longer happens. But the imagerep isn’t what it should be. It’s not null, but it’s a 0x0 with no colorspace and pretty much no data in it at all.

Looks like the “fix” just suppresses the error, but something underlying is still not working."
Comment 6 Jon Goldberger [MSFT] 2016-05-04 22:22:43 UTC
Thanks Chris...

So the issue with the attached test project was my failure to call the this.View.LockFocus() method before instantiating the NSBitmapImageRep and calling this.View.UnlockFocus (); after. i.e.:

>this.View.LockFocus ();
>NSBitmapImageRep newRep = new NSBitmapImageRep (this.View.Frame);
>var x = newRep.BytesPerRow;
>this.View.UnlockFocus ();

this seems to create the NSBitmapImageRep object as expected.

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