Multigrab question and issue.

Official forum for the Chipmunk2D Physics Library.
tetraweb
Posts: 31
Joined: Wed Feb 13, 2013 8:46 pm
Contact:

Multigrab question and issue.

Post by tetraweb »

What's the best way to check which shapes or bodies are currently being grabbed? Can you poll that? Or is there a better way to let for an object to know if it is being grabbed?

Also, an issue I've seen on ipad a few times, my playtester is four years old, and when they go crazy with grabbing objects it seems multigrab will occasionally lock up, with multiple green debug points on the screen staying there. Is there some way to force clear all multigrab points?

Thanks,
Greg
calin
Posts: 30
Joined: Sat Feb 18, 2012 7:58 am
Contact:

Re: Multigrab question and issue.

Post by calin »

You can use the `grabs` property on your ChipmunkMultiGrab object. This will give you an array of ChipmunkGrab objects, which you can use to get the shape being grabbed. For example:

Code: Select all

for (ChipmunkGrab *grab in [_multiGrab grabs]) {
    ChipmunkShape *shape = [grab grabbedShape];
    if (shape) {
        ChipmunkBody *body = [shape body];  // do whatever you want with the body ...
    }
}
For clearing the grabs, you could write an Objective-C category that will remove all objects from the `grabs` array. I don't know if there is another way, but you can experiment.
Note that this is from Chipmunk Pro v6.1.2.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Multigrab question and issue.

Post by slembcke »

The "grabs" array was a somewhat recently added feature, I'd have to check the release notes though. You might have to update to get it.

Another option is that the touch methods return the grab that they are associated with if it's easier process them in a more event based way.
http://chipmunk-physics.net/release/Chi ... _grab.html

As for resetting all of the touch events, there isn't a builtin method to handle that. I guess it makes sense to have though. I'll put it on the list. It really shouldn't be happening unless you are missing touch events from the OS though. Did you forget to implement the touches cancelled event perhaps? I generally just have touches canceled all touches ended directly.

edit: Eek, those Doxygen docs are sort of broken. I'll have to see if I can fix that at all.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
tetraweb
Posts: 31
Joined: Wed Feb 13, 2013 8:46 pm
Contact:

Re: Multigrab question and issue.

Post by tetraweb »

Thanks, Scott. As an aside can I tell you how much fun I am having with Chipmunk. In particular after fighting with Box2d for 8 months; hands down the best thing I did was purchase Chipmunk Pro.

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

Re: Multigrab question and issue.

Post by slembcke »

:D

Thanks. That's really encouraging to hear when people have a good experience with Chipmunk.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
tetraweb
Posts: 31
Joined: Wed Feb 13, 2013 8:46 pm
Contact:

Re: Multigrab question and issue.

Post by tetraweb »

Per above, I had forgotten to implement the touches cancelled event, and that fixed the issue on the ipad with my four year old.

However, I may need to find a way to force clear all the grabs anyway, because I am having an issue where the user drags an object into a container, and the object is then removed from the space, and if the user ends the touch after that object is removed I have an exception here in ccTouchesEnded:

Code: Select all

for(UITouch *touch in touches) {
        ChipmunkGrab *grab = [_multiGrab endLocation:[self convertTouchToNodeSpace:touch]];
        ChipmunkShape *shape = [grab grabbedShape];
Clearly removing an object that is currently being grabbed is problematic. Any ideas?
Greg
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Multigrab question and issue.

Post by slembcke »

Hmm... That's weird. What exactly happens? Since it retains the things that it grabs, that's not supposed to be a problem.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
tetraweb
Posts: 31
Joined: Wed Feb 13, 2013 8:46 pm
Contact:

Re: Multigrab question and issue.

Post by tetraweb »

I'm not exactly sure what is happening. I am using your GameObject class and calling destroy on the object. As soon as I lift the finger off I get the exc_bad_access at

Code: Select all

ChipmunkShape *shape = [grab grabbedShape];
The grab object seems to contain only a pivot joint according to the debugger:

Code: Select all

grab	ChipmunkGrab *	0x005a75c0
NSObject	NSObject	
isa	Class	0x0017d908
_chipmunkObjects	NSArray *	0x005aa000
[0]	ChipmunkPivotJoint *	0x005a9f80
*edit*
Further confusing, if I tap immediately on the scene, while I am still adding chipmunk objects to the scene, I get an exception with:

Code: Select all

Aborting due to Chipmunk error: Grab set is already empty!
	Failed condition: [_grabs count] != 0
	Source:/tmp/ChipmunkPro-TMP/Objective-Chipmunk/ChipmunkMultiGrab.m:210
Hmm.. with zombies enabled I see this in the touchesEnded:

Code: Select all

-[BasicCrate retain]: message sent to deallocated instance 0x555c40
where BasicCrate is my GameObject that has been removed during the grab.
Greg
tetraweb
Posts: 31
Joined: Wed Feb 13, 2013 8:46 pm
Contact:

Re: Multigrab question and issue.

Post by tetraweb »

So I seem to be having two separate issues that I can't resolve.

The first is, I am replacing a cocos2d scene with multigrab with a different scene that has multigrab. If you tap and release in the first few seconds of the second scene I get the exception with this:

Code: Select all

Aborting due to Chipmunk error: Grab set is already empty!
during _multiGrab endLocation.
If I wait a few seconds before tapping the error does not occur. This only happens when replacing one scene with multigrab with another.

The second issue is with removing a GameObject implementing the <ChipmunkObject> protocol during a touch. It does not happen when removing a simple object from the space, only the GameObjects using the GameWorld:remove method. When the object is removed, during the touchesEnded I get the

Code: Select all

-[GameObject retain]: message sent to deallocated instance


I am perplexed.

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

Re: Multigrab question and issue.

Post by slembcke »

So the first issue is caused because you are sending endLocation for a touch that never had a beginLocation. I guess it should just be a warning instead of a hard assertion though. Anyway, I think the underlying issue is that Cocos2D shares the same UIView instance across scenes and doesn't filter events. So it's possible to put your finger down on one scene, transition to another, and then get a touch end event without ever getting a touch began to accompany it. I'm not sure if there's a correct fix for that other than to fix the issue in Cocos2D. Disabling the assertion in ChipmunkMultiGrab would fix everything except in the case of a multi-touch gesture that spanned between two scenes. That's easy enough to avoid though.

As for the second issue, it sounds like it's your game object class that is causing the issue. Your game object gets released when it's removed from the space but the Chipmunk objects still have dangling weak pointers to it through the .data property. What does the stack trace look like where it's happening? ChipmunkMultiGrab shouldn't be accessing the data pointer so I'm not quite sure how that is happening.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests