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...
Status: CONFIRMED
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
URL:
Depends on:
Blocks:
 
Reported: 2015-03-20 10:55 UTC by Chris Hamons
Modified: 2016-09-26 21:59 UTC (History)
4 users (show)

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


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


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 for Bug 28243 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

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.