What? This makes NO since to me at all. In fact when I add a Console.WriteLine("...") right before the call to NSBezierPath.FromOvalInRect(rect), it no longer crashes! I haven't seen errors like this since working with flash? The Console.WriteLine leads me to believe this is some kind of thread / timing issue?? The draw is invoked by SetNeedsDisplayInRect(Bounds). Even more confusing, the NSLabelCellView is only used in an entirely different window and this button object is only used in one other area not related to NSLabelCellView in any way.
Posts
Hmm. It is hard to tell with limited context, but it could be a few things:
a) There could be an issue with the binding where an object not being kept alive. Dump this code somewhere before and see if it shakes things up:
b) Maybe you are doing something from the wrong thread? Confirm all of your drawing calls are on the main thread.
c) What Console.WriteLine "fixes" the issue?
d) Can you please post the full stack trace.
e) Does your NSCellLabelView correctly have an IntPtr constructor and call base on all of its constructors?
f) If none of the above, posting an example may help (less guessing).
a) still crashes
b) I did the following: InvokeOnMainThread(() => SetNeedsDisplayInRect(Bounds)); Also just tried adding InvokeOnMainThread(() => ...) around all the draw code.
c) Console.WriteLine("rect = [{0},{1},{2},{3}]", rect.X, rect.Y, rect.Width, rect.Height);
d)
[External Code]
Followed by:
System.InvalidCastException: Unable to cast object of type 'Musicnotes.Mac.NSLabelCellView' to type 'AppKit.NSBezierPath'
at ObjCRuntime.Runtime.GetNSObject[NSBezierPath] (IntPtr ptr) [0x00121] in /Users/builder/data/lanes/1880/248c95e2/source/maccore/src/ObjCRuntime/Runtime.cs:799
at AppKit.NSBezierPath.FromOvalInRect (CGRect rect) [0x00016] in /Users/builder/data/lanes/1880/248c95e2/source/maccore/src/build/mac/mobile/AppKit/NSBezierPath.g.cs:648
at Musicnotes.Mac.NSCircleImageButton.DrawRect (CGRect dirtyRect) [0x0005a] in /Users/Paul/Code/musicnotes_smv-xamarin/MusicnotesMac/Code/UI/Controls/NSCircleImageButton.cs:78
at at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/1880/248c95e2/source/maccore/src/AppKit/NSApplication.cs:94
at Musicnotes.Mac.MainClass.Main (System.String[] args) [0x00007] in /Users/Paul/Code/musicnotes_smv-xamarin/MusicnotesMac/Code/Main.cs:13
e) yes, it's used in a table and was crashing during implemention before adding that
f) its really hard to post an example given the windows are rich with UI! Sorry I know that is not much help. I will think about it some more.
Thanks.
@ChrisHamons
Well so I came up with a round about way of solving this it seems. I save the path to a member variable then only update it on the "ResizeSubviewsWithOldSize" event.
I know it's not answering the question what the heck is going on but it works so far.