Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-01-2008, 01:02 PM   #1 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 36
Angry Invalid Context Error! Please Advise..

Anyone have any idea how to deal with the following console output?

Code:
<Error>: CGContextSetFillColorWithColor: invalid context
<Error>: CGContextSetStrokeColorWithColor: invalid context
<Error>: CGContextGetShouldSmoothFonts: invalid context
<Error>: CGContextSetFont: invalid context
<Error>: CGContextSetTextMatrix: invalid context
<Error>: CGContextSetFontSize: invalid context
<Error>: CGContextSetTextPosition: invalid context
<Error>: CGContextShowGlyphsWithAdvances: invalid context
The code generating this error message looks like this:

Code:
    CGPoint  location = CGPointMake(50, 200);
    UIFont   *font    = [UIFont systemFontOfSize:21];
    [[UIColor whiteColor] set];
	
    [hello drawAtPoint:location withFont:font];
Thanks in advance,
Mario Velasquez
marioluig is offline   Reply With Quote
Old 10-01-2008, 01:16 PM   #2 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Is that code in some view's drawRect method? It has to be.
PhoneyDeveloper is offline   Reply With Quote
Old 10-01-2008, 01:26 PM   #3 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 36
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
Is that code in some view's drawRect method? It has to be.
Yeah, it is. Any advice?
marioluig is offline   Reply With Quote
Old 10-01-2008, 02:00 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

I assume you're not calling the drawRect yourself and this isn't happening in a secondary thread. There must be some other factor that you're not telling us.

Is this a simple UIView subclass? Does it ever draw correctly? Are you calling super drawRect? Does your app have unexplained crashes? Memory corruption might be the cause.
PhoneyDeveloper is offline   Reply With Quote
Old 10-01-2008, 02:03 PM   #5 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 36
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
I assume you're not calling the drawRect yourself and this isn't happening in a secondary thread. There must be some other factor that you're not telling us.
Yeah. It's being called using the following code:

Code:
	[stopButton addTarget:self action:@selector( drawSquare ) forControlEvents:UIControlEventTouchUpInside];
drawSquare is the method that calls the code in my first post.

Quote:
Originally Posted by PhoneyDeveloper View Post
Is this a simple UIView subclass? Does it ever draw correctly? Are you calling super drawRect? Does your app have unexplained crashes? Memory corruption might be the cause.
Yes.
It draws correctly when you call it from drawRect, but not when you hook it up to a button (see above code)
No explained crashes.

Last edited by marioluig; 10-01-2008 at 02:04 PM. Reason: typo
marioluig is offline   Reply With Quote
Old 10-01-2008, 02:25 PM   #6 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

OK, so you are calling drawRect or the code that you showed directly. You can't do that. To make a view draw itself send setNeedsDisplay. Update whatever state the view needs to draw itself and then send setNeedsDisplay.

You can't draw to a view outside drawRect and you can't call drawRect directly.

The invalid context that is mentioned in the error messages is the CGContext that is required for all drawing. When the framework calls a view's drawRect method it first sets up this context.
PhoneyDeveloper is offline   Reply With Quote
Old 03-10-2010, 03:07 AM   #7 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 3
Default


Try:

setNeedsDisplay on the main thread

[self performSelectorOnMainThread:@selector(setNeedsDisp lay) withObject:0 waitUntilDone:YES];

Last edited by entity2light; 03-10-2010 at 03:10 AM.
entity2light is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 274
19 members and 255 guests
ADY, Alsahir, Dani77, Desert Diva, Duncan C, F_Bryant, Grinarn, HemiMG, Herbie, jansan, linkmx, M@realobjects, macquitzon216, prchn4christ, Robiwan, smethorst, spiderguy84, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,761
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:42 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0