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 09-03-2009, 08:59 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 15
Default Memory Issue

I'm working on an app and the code complies just fine but during runtime the app crashes with the following problem...

GDB: Program received signal: "SIGABRT"
AND SOMETIMES THIS ONE (with no change in code)
“EXC_BAD_ACCESS”

In the Debugger you can see what memory location that is coming from and where it's coming from.

Code:
[timer invalidate];
I've tried different things i've found online but can't seem to get this solved.

Here's the code snipit from where i think the problem is. Let me know if there is something really odd about what i'm doing or if there is a error...or a better way. Any help would be great...it's just frustrating at this point!

Code:
//METHOD TO DETECT MOVEMENT IN iPHONE
- (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler {
	
	if (fabsf(aceler.x) > 2 || fabsf(aceler.y) > 2 || fabsf(aceler.z) > 2) 
	{
		//TEST STATEMENT
		[label setText:@"You shook me!"];
		//SET PROGRESS BAR TO 0
		progressView.progress = 0.0; 
		//INITIALIZE TIMER - SELECTOR TO MOVE PROGRESS
		timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(moveProgress) userInfo:nil repeats: YES];
			
	
	}
}
-(void)moveProgress
{
		progressView.progress = progressView.progress + 0.1;

	
	if (progressView.progress == 0.5)
		{
			[progressLabel setText:@"That's a tough one..."];
		}
			if (progressView.progress == 1.0)
				{
					
					//END TIMER
					
					[timer invalidate]; //PROBLEM????
					
		
				//CREAT ARRAY FROM PLIST (IDENTICAL TO FLIPSIDE LOAD)
					NSString *filePath = [[NSBundle mainBundle] pathForResource:@"answers" ofType:@"plist"];
					//NSLog(filePath);
					NSArray *array = [[NSArray alloc]initWithContentsOfFile:filePath];
					self.answerList1 = array;
					[array release];
					
				//	NSLog(answerList);
				//STORE TOTAL ANSWER LIST COUNT
					int numAnswers = [answerList1 count];
				//RANDOM SELECT AN ARRAY INDEX
					int randSelected = arc4random() % numAnswers;
				//STORE THAT SELECTION AS A STRING (RANDOM PLIST ITEM)
					NSString *selection = [answerList1 objectAtIndex:randSelected];
	
				//OUTPUT THAT RANDOM SELECTION
					[label setText:selection];
					image1.hidden = NO;
					progressView.hidden = YES;
					[progressLabel setText:@""];
					
					NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"fortuneSound" ofType:@"wav"];
					SystemSoundID soundID;
					AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundPath], &soundID);
					AudioServicesPlaySystemSound (soundID);
					
				}
		}
casahome2000 is offline   Reply With Quote
Old 09-04-2009, 04:12 AM   #2 (permalink)
Registered Member
 
pjlocko's Avatar
 
Join Date: Jun 2009
Location: SoCal
Posts: 63
Default

Try:

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:blah blah blah....];

See if thats is any better.
pjlocko is offline   Reply With Quote
Old 09-04-2009, 04:53 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 370
Default

you can't invalidate from its own selector method... right ?
david_david is offline   Reply With Quote
Old 09-04-2009, 07:52 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 34
Default

I think you need to retain the timer after creating it:
Code:
NSTimer *timer = [[NSTimer scheduledTimer...] retain];
datapata is offline   Reply With Quote
Old 09-04-2009, 02:59 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 15
Default More info on Memory Problem

A little bit more info on this.

In the .h file i have the following in the right place...

Code:
NSTimer *timer;
@property (nonatomic,retain) NSTimer *timer;
In the .m file i have the following in the right place...

Code:
@synthesize timer;

- (void)accelerometer:
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(moveProgress) userInfo:nil repeats:YES];

- (void)moveProgress:
[timer invalidate];
I've changed around the code a bit for some of the suggestions but they did not provide any sunshine. I've got it back to what it is posted in my posts now...non functioning! LOL.

Thanks again for helping with this...can't wait to get his resolved.
casahome2000 is offline   Reply With Quote
Old 09-05-2009, 12:45 AM   #6 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 370
Default

hi

Always use self.timer = [NSTimer sch....]; if you set the property
david_david is offline   Reply With Quote
Old 04-28-2010, 10:25 PM   #7 (permalink)
i love this phone
 
Join Date: Mar 2010
Posts: 5
Default thanks

Quote:
Originally Posted by david_david View Post
hi

Always use self.timer = [NSTimer sch....]; if you set the property

your answer helps me solve a problem , thanks!
hxba is offline   Reply With Quote
Reply

Bookmarks

Tags
exc_bad_access, memory, nstimer, sigabrt, timer

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: 283
17 members and 266 guests
2WeeksToGo, ADY, dacapo, Dani77, Fritzer, ghost, HDshot, headkaze, iDifferent, mer10, mystic.purple, Rudy, smethorst, stoneage, superg, tathaastu, Zool
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,878
Threads: 89,224
Posts: 380,732
Top Poster: BrianSlick (7,129)
Welcome to our newest member, olga2000
Powered by vBadvanced CMPS v3.1.0

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