• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: App Crashing when remove an Object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: App Crashing when remove an Object


  • Subject: Re: App Crashing when remove an Object
  • From: Mario Gajardo Tassara <email@hidden>
  • Date: Sat, 29 Mar 2008 13:52:42 -0400


El 28-03-2008, a las 21:08, Sherm Pendley escribió:

On Fri, Mar 28, 2008 at 8:49 PM, Andrew Farmer <email@hidden> wrote:
On 28 Mar 08, at 18:37, Mario Gajardo Tassara wrote:
> In a portion of code of my app (collision detection part) i need to
> remove an object from an array of objects,
> when two distinct objects crashed i decrement a life counter, and
> if this is equal to zero the object must be destroyed, but when the
> counter
> reach de zero and the object is destroyed my app crash. Some one can
> help me with this problem, here is the code, and thanks in advance:


You're removing an object from an array while iterating through it.
Think carefully about what this is doing to the indexes of objects in
the array, and you'll probably see what's going on.

You probably ought to move to some sort of "mark-and-sweep" algorithm
here, rather than mutating the array while iterating through it.

No argument here.

But, if you *do* want to mutate an array while iterating through it, a common approach is to iterate through it backwards. That way, deleting an element will only shift the elements at indexes you've already touched.

sherm--


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden



Following your recommendations, Im trying to implement a "mark-and- sweep" solution to this problem, yesterday i did the backwards iterate aproach but my app still crashed. If someone have another solution please share with me, thanks.



Mario Gajardo Tassara
email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >App Crashing when remove an Object (From: Mario Gajardo Tassara <email@hidden>)
 >Re: App Crashing when remove an Object (From: Andrew Farmer <email@hidden>)
 >Re: App Crashing when remove an Object (From: "Sherm Pendley" <email@hidden>)

  • Prev by Date: Cocoa Tutoring in SF Bay Area
  • Next by Date: Re: machine with null serial number?
  • Previous by thread: Re: App Crashing when remove an Object
  • Next by thread: NSDictionary with bool and float
  • Index(es):
    • Date
    • Thread