Box2D Forums

It is currently Sun Dec 21, 2014 5:05 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue Jan 04, 2011 4:28 pm 
Offline

Joined: Thu May 27, 2010 6:52 am
Posts: 137
If two bodies are touching each other, resting on top of each other, and I destroy one of them, I don't get an EndContact() call. I think it might have something to do with the call getting stuck in Alchemy-land when b2ContactManager destroys a contact (?). Or I could be doing something wrong.

Thanks for any help.

- Doug


Top
 Profile  
 
PostPosted: Tue Jan 04, 2011 7:15 pm 
Offline

Joined: Mon Jul 27, 2009 6:46 am
Posts: 236
Are you destroying from any contact call? Because the world is locked at that point, and you shouldn't delete bodies.

-P


Top
 Profile  
 
PostPosted: Tue Jan 04, 2011 7:59 pm 
Offline

Joined: Thu May 27, 2010 6:52 am
Posts: 137
No, the destroy is done inside a key press listener. Looking deeper into both the C++ and ActionScript, it looks like the world's b2ContactManager class in C++ land has no way of being assigned a b2ContactListener from ActionScript land, so the call just doesn't get made in the first place, or gets made to a b2ContactListener only in C++ land. Could be way off though too :)


Top
 Profile  
 
PostPosted: Wed Jan 05, 2011 2:41 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 915
How are you destroying your body? Are you just removing it from the stage if you're using WCK? is "reportEndContact" definitely true? I'm 99% certain the problem is not something off in alchemy land.


Top
 Profile  
 
PostPosted: Wed Jan 05, 2011 3:19 pm 
Offline

Joined: Thu May 27, 2010 6:52 am
Posts: 137
I use the Alchemy port directly, so in this case I'm just calling b2World::DestroyBody(), which eventually calls lib.b2World_DestroyBody(m_world._ptr, _ptr). In the C++ version of Box2D, this invokes the world's b2ContactManager to make an EndContact() call to its m_contactListener class.

I think everything works fine in Alchemy land, but the call just isn't getting out to my b2ContactListener implementation in ActionScript.

All the report flags are set to true, so normal "EndContacts" get fired, i.e. if I pull the first body off the other body instead of destroying it.


Top
 Profile  
 
PostPosted: Mon Jan 10, 2011 5:10 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 915
Holy smokes, you're right! Here's the problem code (in Alchemy):

Code:
AS3_Val b2World_DestroyBody(void* data, AS3_Val args) {
   b2World* w;
   b2Body* b;
   AS3_ArrayValue(args, "PtrType, PtrType", &w, &b);
   AS3_Release((AS3_Val)b->m_userData);
   for(b2Fixture* f = b->m_fixtureList; f; f = f->m_next) {
      AS3_Release((AS3_Val)f->m_userData);
   }
   for(b2JointEdge* j = b->m_jointList; j; j = j->next) {
      AS3_Release((AS3_Val)j->joint->m_userData);
   }
   w->DestroyBody(b);
   return AS3_Null();
}



See how it's calling AS3_Release on all the fixture userData before calling DestroyBody? Well that means once the end contact event is dispatched, the userData (which points to the AS3 instance) is no longer around to dispatch an event from. Working on a fix...


Top
 Profile  
 
PostPosted: Mon Jan 10, 2011 5:24 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 915
Ok, the latest commit to github should fix this problem. Turns out I didn't even need to release everything there, because I was already doing it in the destruction listener. Of course, alchemy happily marched along as if nothing was wrong.

Sorry I doubted you! I was thinking that if this bug were true, it would wreak havoc on all my other projects.


Top
 Profile  
 
PostPosted: Mon Jan 10, 2011 10:44 pm 
Offline

Joined: Thu May 27, 2010 6:52 am
Posts: 137
Yea it's actually odd that I haven't ran into this before either. Your fix does the trick for me though.

As usual, you're very quick to address issues. I appreciate it.


Top
 Profile  
 
PostPosted: Wed Mar 21, 2012 2:53 pm 
Offline

Joined: Fri Dec 09, 2011 3:10 pm
Posts: 5
Hi, I think I've run into the same problem and I'm just wondering if I've got the latest build. I'm downloading the .ZIP from here https://github.com/jesses/wck. Is there a separate, more up to date github page for the alchemy port without the rest of the wck?

I'm trying to resize a box at runtime which involves destroying and recreating the fixture on the body. b2ContactListener EndContact doesn't seem to be being called when I destroy the fixture. I'll carry on looking just to make certain the problem isn't in my code.


Top
 Profile  
 
PostPosted: Thu Mar 22, 2012 12:32 pm 
Offline

Joined: Fri Dec 09, 2011 3:10 pm
Posts: 5
I solved it by saving all contacts in an associated object and manually removing them when the fixture is destroyed. Not great but it works! I tried changing the fixture without destroying it but box2d didn't seem to only kindof like that. It works but not very well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group