Box2D Forums

It is currently Sat Apr 19, 2014 3:15 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: wck ContactList
PostPosted: Sat Dec 04, 2010 6:59 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 914
A couple of thoughts:

1. Make sure you have "reportEndContact" set to true on all your player's BodyShapes (even nested ones), otherwise contacts will stay in the list forever. Regarding the "nowhere near the player" bug, did the player EVER contact those shapes? Or is it collecting contacts that the player NEVER touched?

2. Notice that "ContactList" has a member, "contactEventFilter". when you call "forEach" or "values" it will only return contact events that pass this filter. "isEmpty" however, does not check this filter. This *may* be why the contact list seems to simultaneously have some / have no contacts.

3. Try instead of "forEach" using the "values" getter. This returns all contacts as an array (after they pass the filter). Since it's an array, you can just use "length" to see if any contact exists at all.

4. If someone could produce a small FLA that demonstrates the ContactList going bonkers that would be really helpful.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Mon Dec 06, 2010 3:22 am 
Offline

Joined: Mon Apr 07, 2008 3:06 am
Posts: 99
Quote:
1. Make sure you have "reportEndContact" set to true on all your player's BodyShapes...

Funny, I could've sworn I had done that, but I was only setting "reportBeginContact". This seems to have fixed it. Thank you!

Quote:
Regarding the "nowhere near the player" bug, did the player EVER contact those shapes? Or is it collecting contacts that the player NEVER touched?

No, it was always objects that had come into contact with the sensors.

...So, I can't help wondering why both flags exist: "reportBeginContact" and "reportEndContact" --if either is true, doesn't the other *have* to also be true?


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Mon Dec 06, 2010 9:06 am 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
@Barliesque
Quote:
...So, I can't help wondering why both flags exist: "reportBeginContact" and "reportEndContact" --if either is true, doesn't the other *have* to also be true?


i frequently use beginContact to detect only when i enter a sensor, for example, golf ball going into a hole. end contact would not be important in this case since i have no need for a ContactList

@maybutter
Quote:
on all your player's BodyShapes
i had thought i might be able to listen to only the feet shape and not bother storing contacts on body/head of the character. i will give this a try, thanks.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Tue Dec 07, 2010 2:38 am 
Offline

Joined: Mon Apr 07, 2008 3:06 am
Posts: 99
Quote:
...end contact would not be important in this case since i have no need for a ContactList

Oh, I see. So, setting these flags doesn't only maintain a ContactList-- it also causes events to be dispatched. Of course! But in the case where you do want to maintain a ContactList, both flags should be true.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Tue Feb 07, 2012 3:21 am 
Offline

Joined: Fri Jan 27, 2012 7:54 am
Posts: 8
I have a custom BodyShape representing a box/bin that contains inside some objects acting as walls, and just a shape that acts as sensor. It's like a bin, and the player must catch some little extern objects with it. To detect when I have got an object, I listen the contacts of this sensor, but not the them from the walls. Inside the create() method of the can object I have this:

Code:
sensor.isSensor = true;
sensor.reportBeginContact = true;
sensor.reportEndContact = true;
         
listenWhileVisible(WCKGameWorld(this.parent), StepEvent.STEP, stepEventHandler, false, 10);
listenWhileVisible(sensor, ContactEvent.BEGIN_CONTACT, beginContactHandler);

contacts = new ContactList();
contacts.listenTo( sensor ); // listen sensor contacts


Inside the STEP event handler ("stepEventHandler") I do:

Code:
contacts.clean();


And inside the BEGIN_CONTACT handler, I process the contacts and then:

Code:
b2Contact(e.contact).SetEnabled(false);
b2Contact(e.contact).destroy();


But when you say:

Quote:
1. Make sure you have "reportEndContact" set to true on all your player's BodyShapes (even nested ones), otherwise contacts will stay in the list forever.


Does it mean that I have to set as true the "reportEndContact" and "reportBeginContact" of the box walls? Now I set them to false also into the create() method, like:

Code:
boxLeftWall.repotBeginContact = false;
boxLeftWall.repotEndContact = false;
boxRightWall.repotBeginContact = false;
boxRightWall.repotEndContact = false;
boxFloor.repotBeginContact = false;
boxFloor.repotEndContact = false;


Are then the contacts for the walls stored in some ContactList that I have to clean?

Thanks for your help


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Tue Feb 07, 2012 11:30 am 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 914
No, if you're setting report...Contact = false on those objects then the contacts will never dispatch and there's nothing you have to "clean". In the comment you quoted I only meant you should pair every reportBegin = true with a reportEnd = true. If they're both false you just don't need to worry about them at all.

I'm not really sure about the purpose of this code:

Code:
b2Contact(e.contact).SetEnabled(false);
b2Contact(e.contact).destroy();


You shouldn't need to SetEnabled(false) because it's already a sensor. And why are you destroying the contact?

The ContactList class is used to maintain a list of running active contacts, like say if you have a player character and you want to always know when they are on the floor. In this case you want to know when the player touches the floor, but also each time step you want to know if the player is still touching the floor. If you're just doing a one time event based off of a beginContactEvent (like removing a collectible coin) the ContactList is probably overkill. Just listen for the BeginContact and remove the bodyShape from the stage (the BodyShape class is smart enough to know to wait until after the timestep to actually remove the b2Body).


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Wed Feb 08, 2012 6:34 am 
Offline

Joined: Fri Jan 27, 2012 7:54 am
Posts: 8
Hi mayobutter, thanks for your reply.

Do you mean that by setting "reportBeginContact" and "reportBeginContact" to false, no contact will be stored?

I use the BEGIN_CONTACT listener to know when an object ist catched by the box and then increase the player's score. What I also do is to adjust this falling object's categoryBits and maskBits so as the sensor doesn't catch them twice.

I also use a BEGIN_CONTACT listener it in an object called scenary (floor and left/right walls) that detects when an object is fallen out from the box and destroys it.

Do you mean that I don't need then to control a ContactList? What I do into my step event listener is to clean this list.

But sometimes I have a serious problem that I thought was related with this contacts management but still have, and is that sometimes my game crashes with the following error:

Code:
Assertion failed: (m_contactCount < m_contactCapacity), function Add, file ../Box2D/Dynamics/b2Island.h, line 74.
[object AlchemyExit]
   at Function/<anonymous>()
   at Function/<anonymous>()
   at Box2DAS.Dynamics::b2World/HandleStep()[/Users/jordi.tost/Projekte/LC Smartboard/flash/wcklib/Box2DAS/Dynamics/b2World.as:162]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at Box2DAS.Common::b2EventDispatcher/dispatchEvent()[/Users/jordi.tost/Projekte/LC Smartboard/flash/wcklib/Box2DAS/Common/b2EventDispatcher.as:27]
   at Box2DAS.Dynamics::b2World/Step()[/Users/jordi.tost/Projekte/LC Smartboard/flash/wcklib/Box2DAS/Dynamics/b2World.as:158]
   at wck::World/step()[/Users/jordi.tost/Projekte/LC Smartboard/flash/wcklib/wck/World.as:198]
Assertion failed: (IsLocked() == false), function DestroyJoint, file ../Box2D/Dynamics/b2World.cpp, line 270.
[object AlchemyExit]
   at Function/<anonymous>()
   at Function/<anonymous>()
   at Box2DAS.Dynamics.Joints::b2Joint/destroy()[/Users/jordi.tost/Projekte/LC Smartboard/flash/wcklib/Box2DAS/Dynamics/Joints/b2Joint.as:32]
   at Function/<anonymous>()[/Users/jordi.tost/Projekte/LC Smartboard/flash/wcklib/wck/Joint.as:614]
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at wck::World/step()[/Users/jordi.tost/Projekte/LC Smartboard/flash/wcklib/wck/World.as:200]


This seems to be a box2d error, and I think that means that the contacts buffer is already full. Because of this I tried to destroy the contact with that 2 lines of code, but seems that it's not the solution and I couldn't fix the bug:

Code:
b2Contact(e.contact).SetEnabled(false);
b2Contact(e.contact).destroy();


The structure of the game is simple. Just has a box, an scenery and dinamically created objects (each second, during a minute) that fall "from the sky". The user must catch the objects with the box, and the scenery removes them when they are not catched.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Wed Feb 08, 2012 7:38 am 
Offline

Joined: Fri Jan 27, 2012 7:54 am
Posts: 8
I found this:

http://quickb2.dougkoellmer.com/forum/v ... p?f=3&t=15

Quote:
It looks like you might have too many objects in your world. How many objects are you creating?

I think something like 1024 is max default.


Does anyone know how to fix it from WCK?

Is I said, I add some objects (one per second), within a duration of 1 minute (60 in total). When day fall out of the stage I remove them (like object.remove()). Maybe Box2D doesn't clear well the memory after the remove()?

Thanks!


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Fri Feb 10, 2012 2:38 am 
Offline

Joined: Fri Jan 27, 2012 7:54 am
Posts: 8
Hi,

I found that this problem is the number of contacts being generated, and occurs inside Alchemy. I'm wondering how could I reduce them, as the game seems to be simple.

I only have 4 walls that limit the stage, a custom shape representing a box (consists of left wall, right wall and floor, and a shape in the middle that acsts as a sensor). With this box, the player must take some objects that fall from the top of the stage during 60 seconds (1 object per second).

With the box's sensor I detect when the user gets an object (I listen begin contact events), and they stay inside the box. What I'm doing here is to change the category bits / mask bits of these objects so as the sensor doesn't detect them again. The stage walls also listen to contacts, and when the objects are not got with the box, I destroy them.

I've noticed that this crash comes when the box is very full of objects, then I suppose they collide with each other and with the box left/right walls and floor. I'm trying to figure it out how to reduce contacts in this case. Is there a way to destroy them?


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Fri Feb 10, 2012 1:13 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 914
Can you post a screenshot of your game? Preferably with the max number of balls when that error shows up. It'll probably be easier to help you along then.


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

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