Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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-30-2008, 09:36 PM   #1 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 279
Default Error.. Kills app.

Ok so I have a time animated bad guy & a missile that shoots at him.

I use this for collision detection..

Code:
if (CGRectContainsRect([myBub1 frame], [missile frame]))
	{
	[myBub1 removeFromSuperview];
	[bubMoveTimer1 invalidate];
	[missileTimer invalidate];
	missile.center = bubView.center;
	missileButtonPressed = NO;
	missile.hidden = YES;
	}
it removes my bad guy, invalidates the movement timers and moves the missile back to my good guy to be fired again.

well that all works perfect but my problem is that when I fire again at the same spot that I killed the last bad guy the missile hits something at the same spot that the bad guy was at and it crashes my app..

It's like my badguy leaves behind his frame when I remove him from the superview & when it goes to remove him again it kills the app (because he's already been removed)

Any ideas??
Kenrik is offline   Reply With Quote
Old 09-30-2008, 09:57 PM   #2 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 279
Default

You know what? I think it's because when I invalidate the movement timer my frame still has it's movement code that gets paused so it removes the image but leaves the frame because it's still stuck in limbo..

that's my theory.. I mean I can't actually see what's happening.


is it possible to make the frames visible? it would help with debugging.

Any ideas? how can I get those frames out of limbo? is there any kind of "SUPER REMOVE" command?
Kenrik is offline   Reply With Quote
Old 10-01-2008, 09:44 AM   #3 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 279
Default

bumpity....
Kenrik is offline   Reply With Quote
Old 10-01-2008, 09:47 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 157
Default

Trying setting the timer to 'nil' after invalidating it.
__________________
Dardan Software
Neil Inglis' Blog
Check out Escape Pod and Alphonetic on iTunes!
Pring is offline   Reply With Quote
Old 10-01-2008, 10:00 PM   #5 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 279
Default

From Apple Docs..

"Discussion
This is the only way to remove a timer from an NSRunLoop object. The NSRunLoop object removes and releases the timer, either just before the invalidate method returns or at some later point.

You must send this message from the thread on which the timer was installed. If you send this message from another thread, the input source associated with the timer may not be removed from its run loop, which could prevent the thread from exiting properly.

The receiver releases its references to the target and userInfo objects at the point of invalidation."

That sucks! because I'm sending the Invalidate command from another thread it's not killing it properly.

Any ideas of how to send a message from my one thread to the other that triggers it.. ?

maybe a BOOL switch with a "if BOOL = YES" [invalidate] type thing?
Kenrik is offline   Reply With Quote
Old 10-01-2008, 10:05 PM   #6 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Code:
performSelectorOnMainThread:
performSelector:onThread:
PhoneyDeveloper is offline   Reply With Quote
Old 10-01-2008, 10:20 PM   #7 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 279
Default

Mega Woot!

That works perfect.. no more crashes!

So for future reference (anyone who searches and finds this thread)

"YOU MUST INVALIDATE A TIMER FROM WITHIN IT'S OWN THREAD"

otherwise it will leave part of the code in limbo indefinitely.

Kenrik 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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 284
18 members and 266 guests
acmecorps, alex_ivanov, ChrisMayer, darrenmj, dmerat, dvaii, Erythema, ianian, iGeorG, jyu, kmadhukishore, Lokendra, markdude, oldmicah, Pilly170, refreshe, robertsechenfen, Rossco
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,238
Threads: 39,016
Posts: 171,113
Top Poster: smasher (2,570)
Welcome to our newest member, Erythema
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:58 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0