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 02-14-2010, 11:32 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
Default EXC_BAD_ACCESS

hello everyone
i was working on a simple game that in which some nsarrays must be initiated with some uibuttons .So i initialized it at the [view did load] later i schedule the main game loop the problem is when the method returns all these data are erased or somehow unexisting and ever since i try and access any of it's elements a runtime error raises (EXC_BAD_ACCESS)
like so:

NSArray *bees;
- (void)viewDidLoad {
[super viewDidLoad];
bees=[NSArray arrayWithObjects:[UIButton buttonWithType:UIButtonTypeRoundedRect],nil];
timer=[NSTimer scheduledTimerWithTimeInterval:1/60 target:self selector:@selector(gameloop) userInfo:nil repeats:YES];
}
-(void)gameloop{
UIButton *temp=[bees objectAtIndex:0];//problem here <----------------
}
sure i made the @synthesize and @proprety;

i ve been searching the internet looking for a solution on where exactly to initiate objects but all i could get is that there is a view did load and a init which i know nothing about
so please if anyone could tell me what's wrong or even point me to an article explaining the viewdidload and it's behavior and the init method
thanks in advance and i hope i can repay u someday.
themaster is offline   Reply With Quote
Old 02-15-2010, 02:14 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 31
Default

Quote:
Originally Posted by themaster View Post
hello everyone
i was working on a simple game that in which some nsarrays must be initiated with some uibuttons .So i initialized it at the [view did load] later i schedule the main game loop the problem is when the method returns all these data are erased or somehow unexisting and ever since i try and access any of it's elements a runtime error raises (EXC_BAD_ACCESS)
like so:

NSArray *bees;
- (void)viewDidLoad {
[super viewDidLoad];
bees=[NSArray arrayWithObjects:[UIButton buttonWithType:UIButtonTypeRoundedRect],nil];
timer=[NSTimer scheduledTimerWithTimeInterval:1/60 target:self selector:@selector(gameloop) userInfo:nil repeats:YES];
}
-(void)gameloop{
UIButton *temp=[bees objectAtIndex:0];//problem here <----------------
}
sure i made the @synthesize and @proprety;

i ve been searching the internet looking for a solution on where exactly to initiate objects but all i could get is that there is a view did load and a init which i know nothing about
so please if anyone could tell me what's wrong or even point me to an article explaining the viewdidload and it's behavior and the init method
thanks in advance and i hope i can repay u someday.
You are creating autorelease array which is deleted when the pool is drained.
You need to retain the NSArray like this:

[[NSArray arrayWithObjects:[UIButton buttonWithType:UIButtonTypeRoundedRect],nil] retain];

Best regards!
mistergod is offline   Reply With Quote
Old 02-15-2010, 09:10 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
Default a very big thank you

Quote:
Originally Posted by mistergod View Post
You are creating autorelease array which is deleted when the pool is drained.
You need to retain the NSArray like this:

[[NSArray arrayWithObjects:[UIButton buttonWithType:UIButtonTypeRoundedRect],nil] retain];

Best regards!
thank u so so much it works like magic
i hope i am not bothering but could u tell me where or when exactly did the pool get drained ?? and what other types behaves the same ?is it every NS,every UI???
and if u don't have time just please point me to any reference or article or any link. you have already helped more than enough
again thanks a lot i hope i can return the favor someday.
themaster is offline   Reply With Quote
Old 02-16-2010, 09:52 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 271
Default

If you're going to retain it then why use the convenience methods? Might as well alloc/init/release and have more control over your memory.
__________________
@rarindeed


Burstly is the only open and free ad management platform for iPhone app developers.
rarindeed is offline   Reply With Quote
Old 02-16-2010, 12:14 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
Default

if you have a better solution point it out
themaster is offline   Reply With Quote
Old 02-16-2010, 03:02 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 31
Default

Quote:
Originally Posted by themaster View Post
thank u so so much it works like magic
i hope i am not bothering but could u tell me where or when exactly did the pool get drained ?? and what other types behaves the same ?is it every NS,every UI???
and if u don't have time just please point me to any reference or article or any link. you have already helped more than enough
again thanks a lot i hope i can return the favor someday.
Here is some useful info:

10 iPhone Memory Management Tips | akosma software

iPhone Dev Center: Memory Management Programming Guide for Cocoa: Introduction

Best regards!
mistergod is offline   Reply With Quote
Old 02-17-2010, 11:24 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
Default thanks

thank you so much mistergod
themaster is offline   Reply With Quote
Reply

Bookmarks

Tags
access, error, gameloop, nsarray

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: 257
22 members and 235 guests
@sandris, AdamL, ADY, Dani77, diyora, FAED, fredidf, F_Bryant, GHuebner, HDshot, JasonR, mer10, Oral B, prchn4christ, Rudy, smithdale87, stekki, tgjorgoski, Thompson22, Touchmint, twerner, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,752
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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