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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-04-2011, 04:33 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Question EXC_BAD_ACCESS with NSNumber

Hi, I can't figure out why this code is giving an EXC_BAD_ACCESS. I've tried retaining, casting, and removing the "intValue" on the NSNumbers to no avail. What am I doing wrong?

Code:
-(IBAction)startCalc:(id)sender
{
	if (timer == nil) 
	{
		timer = [NSTimer scheduledTimerWithTimeInterval:0.75 target:self selector:@selector(updateProbability) userInfo:nil repeats:YES];
	}
	if (count == nil) 
	{
		count = [NSMutableArray array];
		for (int i = 0; i < range; i++)  //Range is non-zero
		{
			[count addObject:[NSNumber numberWithInt:0]];
		}
	}
}

-(void)updateProbability
{
	NSLog(@"Updating: %i", range);
	int i = rand() % range;
	NSLog(@"%i", i);
	NSLog(@"Should be %@ or %i", [count objectAtIndex:i], [[count objectAtIndex:i] intValue]); //Gives error here or on below line when NSLog is not present
	int j = [[count objectAtIndex:i] intValue];
	NSLog(@"J: %i", j);
	j++;
	[count replaceObjectAtIndex:i withObject:[NSNumber numberWithInt:j]];
	[self setPercentagesAndUpdate];
}
architectpianist is offline   Reply With Quote
Old 04-04-2011, 05:05 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Mission Viejo, CA
Age: 30
Posts: 271
Brandt is on a distinguished road
Default

What does the stack trace say?
Brandt is offline   Reply With Quote
Old 04-04-2011, 07:04 PM   #3 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You aren't using a property when assigning an object to 'count', and you are assigning it an autoreleased object. It's probably being released by the time you want to use it. Use properties.
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
exc_bad_access, intvalue, nsnumber, random

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: 368
13 members and 355 guests
condor304, dansparrow, dre, ilmman, LezB44, michelle, Nobbsy, Objective Zero, samdanielblr, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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