iphone Objective C chipmunk: addPostStepCallback

Official forum for the Chipmunk2D Physics Library.
Post Reply
andrews
Posts: 16
Joined: Wed Apr 27, 2011 5:35 am
Contact:

iphone Objective C chipmunk: addPostStepCallback

Post by andrews »

Searched for addPostStepCallback but no luck so I am posting a question..

I am trying to remove shapes from the space, so based on the documentation I am adding a callback:

Code: Select all

[space addPostStepCallback:self selector:@selector(postStepCallback:) key:shape5];

but I get

Code: Select all

[ChipmunkSpace addPostStepCallback:selector:key:]: unrecognized selector sent to instance

Any insight why?

Thanks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: iphone Objective C chipmunk: addPostStepCallback

Post by slembcke »

What version are you using? The declaration from the 5.3.4 header looks like this:

Code: Select all

- (void)addPostStepCallback:(id)target selector:(SEL)selector key:(id)key;
It was added in one of the 5.3.x versions to replace the following method that was broken in a way that I couldn't fix without deprecating and replacing it.

Code: Select all

- (void)addPostStepCallback:(id)target selector:(SEL)selector context:(id)object __attribute__((deprecated));
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
andrews
Posts: 16
Joined: Wed Apr 27, 2011 5:35 am
Contact:

Re: iphone Objective C chipmunk: addPostStepCallback

Post by andrews »

we bought the objective c wrapper, Objective-Chipmunk-5.3.3.tgz(libObjectiveChipmunk-iPhone.a), Objective-Chipmunk-5.3.3/html/index.html [strangely enough, the page says: "Objective-Chipmunk API reference. 5.3.2" - maybe it was not updated]

I am able to jump to this method from the code by clicking on the method signature, but during runtime it gives me the error.

libObjectiveChipmunk-iPhone.a has Tuesday, December 7, 2010 stamp on it.

UPDATE:
It seems that the trial version of the chipmunk was newer than 5.3.3, so somehow when I copied over the 5.3.3 files it only detected on runtime that the method does not exist.

What is the latest version? If higher than 5.3.3 can we upgrade?

There is another libObjectiveChipmunk.a. What is the difference between libObjectiveChipmunk.a and libObjectiveChipmunk-iPhone.a?

/**
Define a callback to be run just before [ChipmunkSpace step:] finishes.
The main reason you want to define post-step callbacks is to get around the restriction that you cannot call the add/remove methods from a collision handler callback.
Post-step callbacks run right before the next (or current) call to ChipmunkSpace.step: returns when it is safe to add and remove objects.
You can only schedule one post-step callback per context value, this prevents you from accidentally removing an object twice. Registering a second callback for the same object will replace the first.

The method signature of the method should be:
@code
- (void)postStepCallback:(id)key</code></pre>
@endcode

This makes it easy to call a removal method on your game controller to remove a game object that died or was destroyed as the result of a collision:
@code
[space addPostStepCallback:gameController selector:@selector(remove:) key:gameObject];
@endcode

@attention Not to be confused with post-solve collision handler callbacks.
@warning @c target and @c object cannot be retained by the ChipmunkSpace. If you need to release either after registering the callback, use autorelease to ensure that they won't be deallocated until after [ChipmunkSpace step:] returns.
@see ChipmunkSpace.addPostStepRemoval:
*/
- (void)addPostStepCallback:(id)target selector:(SEL)selector key:(id)key;
andrews
Posts: 16
Joined: Wed Apr 27, 2011 5:35 am
Contact:

Re: iphone Objective C chipmunk: addPostStepCallback

Post by andrews »

I will try to use the 5.3.3 calls until/if we get the 5.3.4.

BUT
[space addPostStepCallback:self selector:@selector(postStepCallback:) context:shape5];

is crashing also.

(gdb) bt
#0 0x32ffeca4 in objc_msgSend ()
#1 0x00017dec in postStepPerform (unused=<value temporarily unavailable, due to optimizations>, obj=0x175d20, data=<value temporarily unavailable, due to optimizations>) at /Users/slembcke/Development/Objective-Chipmunk/ChipmunkSpace.m:283
#2 0x0001b3bc in postStepCallbackSetIter (callback=0x18fe60, space=<value temporarily unavailable, due to optimizations>) at /Users/slembcke/Development/Objective-Chipmunk/../Chipmunk/src/cpSpaceStep.c:265
#3 0x000125ec in cpHashSetEach (set=0x18fe00, func=0x1b398 <postStepCallbackSetIter>, data=0x18a474) at /Users/slembcke/Development/Objective-Chipmunk/../Chipmunk/src/cpHashSet.c:224
DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece.
#4 0x0001b97c in cpSpaceStep (space=0x18a474, dt=) at /Users/slembcke/Development/Objective-Chipmunk/../Chipmunk/src/cpSpaceStep.c:381
#5 0x000194f8 in -[ChipmunkSpace step:] (self=<value temporarily unavailable, due to optimizations>, _cmd=<value temporarily unavailable, due to optimizations>, dt=<value temporarily unavailable, due to optimizations>) at /Users/slembcke/Development/Objective-Chipmunk/ChipmunkSpace.m:392
#6 0x00006fb4 in -[GameViewController update] (self=0x175d20, _cmd=0x31c5ebd8) at GameViewController.m:621
#7 0x34c37bea in CA::Display::DisplayLink::dispatch ()
#8 0x34c37d12 in CA::Display::IOMFBDisplayLink::callback ()
#9 0x366c99c6 in IOMobileFramebufferVsyncNotifyFunc ()
#10 0x31d696ea in IODispatchCalloutFromCFMessage ()
#11 0x32b0dbde in __CFMachPortPerform ()
#12 0x32b18a96 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#13 0x32b1a83e in __CFRunLoopDoSource1 ()
#14 0x32b1b60c in __CFRunLoopRun ()
#15 0x32aabec2 in CFRunLoopRunSpecific ()
#16 0x32aabdca in CFRunLoopRunInMode ()
#17 0x3202e41e in GSEventRunModal ()
#18 0x3202e4ca in GSEventRun ()
#19 0x3194dd68 in -[UIApplication _run] ()
#20 0x3194b806 in UIApplicationMain ()
#21 0x0000240e in main (argc=1, argv=0x2fdff584) at main.m:14
(gdb)


Do you by any chance have a working call for addPostStepCallback. I need to remove old shapes when I reset my game.


If I use
[space addPostStepRemoval:shape5];

I get:
(gdb) bt
#0 0x32ffec9a in objc_msgSend ()
#1 0x00017dec in postStepPerform (unused=<value temporarily unavailable, due to optimizations>, obj=0x1ba120, data=<value temporarily unavailable, due to optimizations>) at /Users/slembcke/Development/Objective-Chipmunk/ChipmunkSpace.m:283
#2 0x0001b3bc in postStepCallbackSetIter (callback=0x1bfbd0, space=<value temporarily unavailable, due to optimizations>) at /Users/slembcke/Development/Objective-Chipmunk/../Chipmunk/src/cpSpaceStep.c:265
#3 0x000125ec in cpHashSetEach (set=0x1bfb70, func=0x1b398 <postStepCallbackSetIter>, data=0x1ba124) at /Users/slembcke/Development/Objective-Chipmunk/../Chipmunk/src/cpHashSet.c:224
DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece.
#4 0x0001b97c in cpSpaceStep (space=0x1ba124, dt=) at /Users/slembcke/Development/Objective-Chipmunk/../Chipmunk/src/cpSpaceStep.c:381
#5 0x000194f8 in -[ChipmunkSpace step:] (self=<value temporarily unavailable, due to optimizations>, _cmd=<value temporarily unavailable, due to optimizations>, dt=<value temporarily unavailable, due to optimizations>) at /Users/slembcke/Development/Objective-Chipmunk/ChipmunkSpace.m:392
#6 0x00006fb4 in -[GameViewController update] (self=0x1a59f0, _cmd=0x31c5ebd8) at GameViewController.m:621
#7 0x34c37bea in CA::Display::DisplayLink::dispatch ()
#8 0x34c37d12 in CA::Display::IOMFBDisplayLink::callback ()
#9 0x366c99c6 in IOMobileFramebufferVsyncNotifyFunc ()
#10 0x31d696ea in IODispatchCalloutFromCFMessage ()
#11 0x32b0dbde in __CFMachPortPerform ()
#12 0x32b18a96 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#13 0x32b1a83e in __CFRunLoopDoSource1 ()
#14 0x32b1b60c in __CFRunLoopRun ()
#15 0x32aabec2 in CFRunLoopRunSpecific ()
#16 0x32aabdca in CFRunLoopRunInMode ()
#17 0x3202e41e in GSEventRunModal ()
#18 0x3202e4ca in GSEventRun ()
#19 0x3194dd68 in -[UIApplication _run] ()
#20 0x3194b806 in UIApplicationMain ()
#21 0x00002426 in main (argc=1, argv=0x2fdff584) at main.m:14
(gdb)

Thanks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: iphone Objective C chipmunk: addPostStepCallback

Post by slembcke »

Hmm. I sent out Objective-Chipumkn 5.3.4 on Dec 13 a few days later with a couple of bug fixes that slipped testing. Did you not get the update or did we just send you the wrong version? Sorry about that. What email address do you want me to send it to? The one you registered your forum account to?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
andrews
Posts: 16
Joined: Wed Apr 27, 2011 5:35 am
Contact:

Re: iphone Objective C chipmunk: addPostStepCallback

Post by andrews »

Thanks a lot. We will send you from the original email we asked for the license for an updated copy. We will refer to this discussion.

In any case, do you by any chance have a working call for addPostStepCallback. I need to remove old shapes when I reset my game.
The samples that were included do not contain any addPostStepCallback solution.

Thanks again!
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests