Chap12: digger animations

This is the official forum for Learning Cocos2D: A Hands-On Guide to Building iPhone and iPad Games with Cocos2D, Box2D, and Chipmunk by Rod Strougo and Ray Wenderlich, published by Addison-Wesley.

Chap12: digger animations

Postby rbrosseau » Thu Jun 21, 2012 12:32 am

Digger has 2 animation which are declared as plain non-decorated pointers.
I've been getting crashes when playing these animations and the values in the object appear to be 'junk'.
I think these animation variables need to be declared in the same manner as all the other animations for the other game objects - that is, as retained pointers, in order not to get garbage-collected.
The following pattern should be added in digger.h
Code: Select all
@property (nonatomic, retain) CCAnimation *rotateAnim;
@property (nonatomic, retain) CCAnimation *drillAnim;

and the corresponding '@synth..." in the .mm file

This seemed to clear up the problem in my version...
rbrosseau
Hacker
 
Posts: 30
Joined: Tue Apr 24, 2012 1:51 am
Has thanked: 0 time
Been thanked: 1 time

Re: Chap12: digger animations

Postby larry » Sun Jun 24, 2012 7:10 am

@rbrosseau,
What's a plain non-decorated pointer? I'm guess you mean that there's no "@property (non atomic, retain)".

When I went through the book, I didn't have to do the change you mentioned.

Looks like you have solved it already.

Next time you need help (or want to compare expectations), what version of XCODE and COCOS2D are you running? Do you have the original error message? When following along in the book, the authors have published a working copy of the code here: http://cocos2dbook.com/cocos2d/sourcecode/.
larry
Uber Haxx0r
 
Posts: 294
Joined: Sun Oct 09, 2011 6:11 am
Has thanked: 2 times
Been thanked: 28 times

Re: Chap12: digger animations

Postby n_dubbs » Mon Jun 25, 2012 5:06 pm

@rbrosseau there is no garbage collection in iOS. If you're object has a junk value, then it may have been autoreleased or never set in the first place.
User avatar
n_dubbs
Forum Subject Matter Expert
 
Posts: 885
Joined: Fri Feb 18, 2011 7:17 pm
Location: Pittsburgh, PA
Has thanked: 0 time
Been thanked: 33 times

Re: Chap12: digger animations

Postby kolpaque » Mon Jun 25, 2012 5:26 pm

While we are in a Digger thread... Was it publisher's mistake not to include "digger_wheel.png" file into the atlas?
kolpaque
Uber Haxx0r
 
Posts: 76
Joined: Tue Apr 10, 2012 8:41 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Chap12: digger animations

Postby rbrosseau » Mon Jun 25, 2012 11:20 pm

Sorry guys, I meant autoreleased.
I'm not sure why other people haven't seen this issue before but this isn't the first time that this board has seen discussions on crashes happening to some and not to others. There was the strangely initialized gameObject a couple of weeks ago that I helped someone on and the scene 1 errors on destroyed objects.

I don't yet quite understand the under-the-covers happenings with objective-C and the autorelease. I'll have to go back and review the language.

As far as the digger_wheel.png, just copy wheel.png and make it larger to fit digger. I also desaturated it and made it darker so it fits in with the rest of digger.
rbrosseau
Hacker
 
Posts: 30
Joined: Tue Apr 24, 2012 1:51 am
Has thanked: 0 time
Been thanked: 1 time

Re: Chap12: digger animations

Postby rbrosseau » Mon Jun 25, 2012 11:57 pm

So, upon re-examining the code I noticed I had omitted the lines after creating the animation that added the anim to the CCAnimationCache. Without the animation cache holding on to the alloced animation I guess they were autoreleased.
rbrosseau
Hacker
 
Posts: 30
Joined: Tue Apr 24, 2012 1:51 am
Has thanked: 0 time
Been thanked: 1 time

Re: Chap12: digger animations

Postby kolpaque » Tue Jun 26, 2012 3:06 am

I have no clue myself what happens with the memory management, i know that objects are getting retained once they are passed to another object, or initialized in some class, so the class retains it and responsible for releasing it, unless it passes it.. also depends on what type of obect it is, for example properties can be retain type or release... it's so confusing. It is probably something that will come with experience after writing lots and lots of code and digging through errors and stuff...

For digger_wheel.png i just commented lines of code out of the digger.mm when it is trying to assign wheelL and wheelR sprites using sprite frame as "digger_wheel.png" which doesn't exist.. and commented out lines of code out of createDigger in the scene4ActionLayer.mm where it is trying to add Child as wheelL and wheelR. Coz we want only bodies to be there anyways.. so sprites can go and rest on this one
kolpaque
Uber Haxx0r
 
Posts: 76
Joined: Tue Apr 10, 2012 8:41 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Chap12: digger animations

Postby n_dubbs » Wed Jun 27, 2012 12:51 pm

User avatar
n_dubbs
Forum Subject Matter Expert
 
Posts: 885
Joined: Fri Feb 18, 2011 7:17 pm
Location: Pittsburgh, PA
Has thanked: 0 time
Been thanked: 33 times


Return to Learning Cocos2D Book Official Forum

Who is online

Users browsing this forum: No registered users and 3 guests