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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 02-16-2010, 01:42 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: Stockholm, Sweden
Posts: 38
Jompe71 is on a distinguished road
Default "Random" EXC_BAD_ACCESS in quarz.

I'm (a newbee) trying to port an old game into IPhone.

The problem Im facing is a crash rendering (using Quartz) the current scene in a UIView from setNeedsDisplay. At random points in a rendering method I get EXC_BAD_ACCESS. Using the debugger it seem to occur at random code lines.

The 1st rendering scene always works fine, but when I call setNeedsDisplay from a touch event and try to render the 2nd scene I get the crash.

Note that the rendering methods in the UIView derived class is static, but I changed it into non static, same result.

Anyone got the same problem ?

Code:
-( void )drawRect:( CGRect )rect {

	CGContextRef ctx = UIGraphicsGetCurrentContext();

	switch( renderMode ) {
	
		case RENDER_MODE_TITLE:
			[ MasqueradeDeluxeView renderTitleMode:ctx ];
			break;
			
		case RENDER_MODE_SELECT_GAME:
			[ MasqueradeDeluxeView renderSelectGameMode:ctx ];
			break;
			
		case RENDER_MODE_MENU:
			[ MasqueradeDeluxeView renderMenuMode:ctx ];
			break;
			
		case RENDER_MODE_OPTIONS:
			[ MasqueradeDeluxeView renderOptionsMode:ctx ];
			break;	
	}
	//CGContextFlush( ctx );
}
Code:
///
/// Renders the title mode.
///
+( void )renderTitleMode:( CGContextRef )ctx {

	CGContextTranslateCTM( ctx, 0, background.size.height );
	CGContextScaleCTM( ctx, 1.0, -1.0 );
	CGContextDrawImage( ctx, CGRectMake( 0, 0, 480, 320 ), background.CGImage );
	
	[ MasqueradeTextHandler drawTextRoundedSelection:ctx bounds:titleFrame cornerRad:10 ];
	[ MasqueradeTextHandler drawFixedWidthStringCentered:ctx x:SCREEN_WIDTH >> 1 y:30 text:@"PRESS TO START..." ];
}
Code:
///
/// Renders the menu mode.
///
+( void )renderMenuMode:( CGContextRef )ctx {

	CGContextTranslateCTM( ctx, 0, background.size.height );
	CGContextScaleCTM( ctx, 1.0, -1.0 );
	CGContextDrawImage( ctx, CGRectMake( 0, 0, 480, 320 ), background.CGImage );

	for( int mo = MENU_OPTIONS.count -1; mo >= 0 ; mo-- ) {
	
		CGRect moRect = menuFrames[ mo ];
		int x = moRect.origin.x + ( ( int )moRect.size.width >> 1 );
		[ MasqueradeTextHandler drawTextRoundedSelection:ctx bounds:menuFrames[ mo ] cornerRad:10 ];
		[ MasqueradeTextHandler drawFixedWidthStringCentered:ctx 
														   x:x
														   y:30 
														text:[ MENU_OPTIONS objectAtIndex: mo ] ];	
	} 
}
Code:
///
/// Renders a rounded rect of supplied bounds and radius on the corners.
/// Fill and rect color are globally setup from initialize.
///
+( void )drawTextRoundedSelection:( CGContextRef )ctx bounds:( CGRect )b cornerRad:( int )cr {
	
	CGContextSetLineWidth( ctx, 2.0F );
	CGContextSetStrokeColorWithColor( ctx, optionsRectColor ); 
	CGContextSetFillColorWithColor( ctx, optionsSelectedColor );
	CGContextSetShouldAntialias( ctx, TRUE );
	
	CGFloat minx = CGRectGetMinX( b );
	CGFloat midx = CGRectGetMidX( b );
    CGFloat maxx = CGRectGetMaxX( b );
    CGFloat miny = CGRectGetMinY( b );
    CGFloat midy = CGRectGetMidY( b );
    CGFloat maxy = CGRectGetMaxY( b );
	
	CGContextMoveToPoint( ctx, minx, midy );
    CGContextAddArcToPoint( ctx, minx, miny, midx, miny, cr );
    CGContextAddArcToPoint( ctx, maxx, miny, maxx, midy, cr );
    CGContextAddArcToPoint( ctx, maxx, maxy, midx, maxy, cr );
    CGContextAddArcToPoint( ctx, minx, maxy, minx, midy, cr );
    CGContextClosePath( ctx );
    CGContextDrawPath( ctx, kCGPathFillStroke );
}
The crash seems to be random at any point calling the CG* method from within the drawTextRoundedSelection method.

URGENT!!
If the question isn't formulated (sorry for the poor english), please let me know and I'll reformulate dito.

Last edited by Jompe71; 02-16-2010 at 01:51 PM.
Jompe71 is offline   Reply With Quote
Old 02-16-2010, 03:16 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 70
firebug is on a distinguished road
Default

Don't know if this will help at all but the only time I've seen or heard of "random" crashing, it was always caused by a timer. So make sure you aren't trying to call a method from a released timer and your methods that are called from a timer aren't using anything that is released.
firebug is offline   Reply With Quote
Old 02-16-2010, 04:38 PM   #3 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Have you cleaned all targets and stuff?
ZunePod is offline   Reply With Quote
Old 02-17-2010, 06:47 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: Stockholm, Sweden
Posts: 38
Jompe71 is on a distinguished road
Default

Quote:
it was always caused by a timer.
Have to Timer at this stage. Later though...

Quote:
Have you cleaned all targets and stuff?
Hmmm... probably NO. If it isn't done automagic by a computer reboot and XCode restart etc. Problem have been around for some time now.
Jompe71 is offline   Reply With Quote
Reply

Bookmarks

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: 396
8 members and 388 guests
13dario13, iOS.Lover, JackReidy, jeroenkeij, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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