I've been sitting at home sick for over a month, trying to keep sane by 
re-learning Cocoa. I am just about to complete my first non-trivial Cocoa 
application.  The application is working perfectly, including no memory 
management issues, but I've been constantly checking the console so I can make 
sure I don't miss any subtle problems.  Unfortunately, I'm getting strange 
error messages in the console when the application's main window first opens.

The window contains, among standard controls, two custom NSViews:
        1. An x-y plot of data.
        2. A drawing of a color-filled circle created in the custom view's 
drawRect: method.  All that's used are the standard NSColor and NSBezierPath 
classes. Pretty trivial stuff.  Two copies of these views are used in the 
window as a figure legends for the plot.

In the window's awakeFromNib: method, the model class is created and 
initialized, then the two legend custom views are assigned their colors.  

When the figure legends' drawRect: method is executed, the console spits out 
about 50 or so Core Graphics errors stating that there's an invalid CGContext 
for anything from setting line width to setting a line  join, and so on -- I 
assume all of this stuff is going on in the background since I'm not doing any 
direct Core Graphics calls. The errors are triggered by each of the following 
lines of code:
        1. Erasing the background with NSRectFill( [self bounds] ).
        2. Setting the color using [[NSColor blackColor] set].
        3. Drawing the circle outline with [[NSBezierPath 
bezierPathWithOvalInRect: theLegendFrame] stroke], where theLegendFrame is a 
local copy of the view's bounds.
        4. Setting the color with [[self legendColor] set];, where the 
legendColor is the color assigned as mentioned above.
        5. Filling the circle (after the framing NSRect is inset) with 
[[NSBezierPath bezierPathWithOvalInRect: theLegendFrame] fill];

Surprisingly, there are no such errors in my plot drawing code, and it's a lot 
more complicated!

I am completely puzzled by these errors because I thought that using simple 
Cocoa drawing classes solely within drawRect: meant that CGContents would not 
have to be set manually (at least that's what code examples in my books and on 
the web say). I've been scouring the Apple documentation, mailing lists, web 
sites -- anything that could give a clue before asking a potentially stupid 
newbie question. I know that I'm having difficulty concentrating, so forgive me 
if I'm coming across like a complete idiot or missing a blatantly obvious fact. 
Could you please point me to where I can start to look for a solution to these 
CGContext problems?

Thank you.

Scott




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to