A bug? (Passing through a static body)

Something bad happens (in the svn version, ok in 1.4.2)
if I change the line in b2Settings.h
from
const int32 b2_maxPolyVertices = 8;
to
const int32 b2_maxPolyVertices = 16;

Update:
It happens in the Testbed btw..
I have the stack trace
TestBed.exe!b2BlockAllocator::Allocate(int size=544) Line 101 + 0x20 bytes C++
TestBed.exe!b2Shape::Create(const b2ShapeDef * def=0x0012fdf0, b2Body * body=0x01441824, const b2Vec2 & center={...}) Line 216 + 0x10 bytes C++
TestBed.exe!b2Body::b2Body(const b2BodyDef * bd=0x0012fcc0, b2World * world=0x01410068) Line 114 + 0x17 bytes C++
TestBed.exe!b2World::CreateBody(const b2BodyDef * def=0x0012fcc0) Line 73 + 0x31 bytes C++
TestBed.exe!PolyCollision::PolyCollision() Line 39 + 0x12 bytes C++
TestBed.exe!PolyCollision::Create() Line 65 + 0x22 bytes C++
TestBed.exe!main(int argc=1, char * * argv=0x003e3f48) Line 225 + 0xd bytes C++
TestBed.exe!__tmainCRTStartup() Line 327 + 0x19 bytes C
TestBed.exe!mainCRTStartup() Line 196 C



Mike
Seems to work ok for me.

(Even though my sensors-hack stopped working - I added some objects to another world and used b2CollidePoly manually - oh well)
I put in a fixed for non-centered polygons into SVN. The polygon position is now the centroid, regardless of the position of the polygon on the parent body. So far I have fixed 2 bugs with polygon collision.

Is anyone available to test the SVN version?

Mike: your crash is unrelated. The code correctly crashed because the block allocator did not support a block large enough to hold a polygon with 16 vertices. Some stuff got added to polygons recently for CCD. So I added a max block size of 640 bytes (was 512).

Demo: if you have time, I would gladly accept a patch to handle sensors. It's on my TODO list, but I need to finish CCD first.
Great, That did it! 🙂
Thanks!
Mike
If I get around to making something that makes sense with sensors, I'll submit it.
What I did first was only to use the code already present to handle the collision detection in an very manual way.
Just looping through the shapes I knew where interseting and testing for collisions.

The solution that seems easiest to me is to have a bit per shape that simply flags that object as "do not apply physics", so the rest of the library is left untouched. Perhaps another variable in the shape class has an unused bit I can use...
I tested with the newest SVN version and it works perfectly. No more collision bugs.

Thanks,
Petri
I also tested the latest, with the 'E' shape, and the main bug is now gone (the popping).

There is still a slight instability, but it turns out it comes from the fact that my decomposition algorithm occasionally creates collinear points without joining the segments (with assertions enabled, it dies during the convexity test). I'm going to add a test for this and merge any segs that are along the same line. Am I correct that there's no decent way for SAT to handle collinear segments, so this should be worked around at the shape generation level? b2PolyShape tests the cross products of the normals against epsilon; is this absolutely necessary, or could testing against zero replace that check without ill effects?
The polygon collision uses clipping to find contact points. If you don't merge collinear segments, you will get a nice rocking motion. 😉

If anything, I think that test should be stricter. Please merge segments agressively. Perhaps we can place an angular tolerance in the settings that will be shared by your merge code and the convexity test.
Hi, I'm playing with actionscript3 port of this engine.
At the beginning i wanted to understand what can be done, and how it can be done with box2d.

I created some complex shapes. But there seems to be bug where small poligon shapes tend to pass through other poligon shapes, and even accelerate while doing it. (I created basked - movable, and small boxes seem to pass through baskets skewed sides)
I tried to compare svn versions and see what changes have been done to fix this (or similar) issue in C++ version. But code looks like pretty much different.

Maybe somebody has fixed this issue in AS3 port already, or AS3 port or Box2d Does not support that kind of shapes ?

Attachment:
basket.jpg
basket.jpg [ 34.39 KiB | Viewed 331 times ]


Code for this example:
Code:
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty.  In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/


package TestBed{
   
   
   
   import Engine.Dynamics.*;
   import Engine.Collision.*;
   import Engine.Collision.Shapes.*;
   import Engine.Dynamics.Joints.*;
   import Engine.Dynamics.Contacts.*;
   import Engine.Common.*;
   import Engine.Common.Math.*;
   
   
   
   public class TestExample extends Test{
      
      public function TestExample(){
         
         // Set Text field
         Main.m_aboutText.text = "Example";
         
         var ground:b2Body = m_world.m_groundBody;
         var bd:b2BodyDef;
         var body:b2Body;
         var circ:b2CircleDef    = new b2CircleDef();
         var box:b2BoxDef       = new b2BoxDef();
         var myBox:b2BoxDef       = new b2BoxDef();
         
         var basketBox1:b2BoxDef = new b2BoxDef();
         var basketBox2:b2BoxDef = new b2BoxDef();         
         var basketBox3:b2BoxDef = new b2BoxDef();
         var basketBody:b2BodyDef = new b2BodyDef();         
         var jd:b2RevoluteJointDef
         var i:int;
         var angle:Number;
         var tX:Number;
         var tY:Number;

         // Create basket
         {
            basketBox1.extents.Set(40 / m_physScale, 5 / m_physScale);
            basketBox1.localPosition.Set(-60/ m_physScale,20 / m_physScale);
            basketBox1.localRotation = 45 / 180 * Math.PI;
            basketBox1.density = 1;
            basketBox1.restitution = 0.5;
            basketBox1.friction = 1;
            
            basketBox2.extents.Set(40 / m_physScale, 5 / m_physScale);            
            basketBox2.localPosition.Set(60/ m_physScale,20 / m_physScale);
            basketBox2.localRotation = -45 / 180 * Math.PI;
            
            basketBox2.density = 1;
            basketBox2.restitution = 0.5;
            basketBox2.friction = 1;            
                        
            basketBox3.extents.Set(30 / m_physScale, 5 / m_physScale);
            basketBox3.localPosition.Set(0/ m_physScale,50 / m_physScale);
            
            basketBox3.density = 1;
            basketBox3.restitution = 0.5;
            basketBox3.friction = 1;                        
                        
            basketBody.AddShape(basketBox1);
            basketBody.AddShape(basketBox2);
            basketBody.AddShape(basketBox3);
            
            basketBody.position.Set(260 / m_physScale, 155 / m_physScale);
            
            m_world.CreateBody(basketBody);
         }
         
         // Create plane, ball and dominoes
         {
            
            // excentic hammer
            circ.radius = 10 / m_physScale;
            circ.density = 1;
            circ.friction = 0.5;
            circ.restitution = 0;
            bd = new b2BodyDef();
            bd.AddShape(circ);
            myBox.extents.Set(70 / m_physScale, 3 / m_physScale);
            myBox.localPosition.Set(0,50 / m_physScale);
            myBox.density = 5;
            myBox.localRotation = 0.5 * Math.PI;
            bd.AddShape(myBox);
            bd.position.Set(160 / m_physScale, 55 / m_physScale);
            m_world.CreateBody(bd);
            
         }
         
         // Box, ramp, and circle
         {
            // Simple Cirlce
            circ.radius = 15 / m_physScale;
            circ.density = 1;
            circ.friction = 0.5;
            circ.restitution = 1;
            bd = new b2BodyDef();
            bd.AddShape(circ);
            bd.position.Set(510 / m_physScale, 120 / m_physScale);
            m_world.CreateBody(bd);
            
         }
         
         // Stack of small boxes
         {
            // box
            box.extents.Set(7 / m_physScale, 7 / m_physScale);
            box.friction = 1;
            box.density = 0.5;
            bd = new b2BodyDef();
            bd.AddShape(box);
            for (var x:int = 0; x < 3; x++){
               for (var y:int = 0; y < 15; y++){
                  bd.position.Set((50 + x * 16) / m_physScale, (348 - y * 13.5) / m_physScale);
                  body = m_world.CreateBody(bd);
                  body.m_flags |= b2Body.e_sleepFlag;
               }
            }
         }
      }
   }
}


Thanks
Perhaps skatehead (Matt) can answer this best, but I believe the flash port is not up to 1.4.3 yet (which has the fix). Box2D should work fine for the shapes you showed.

Original thread: https://box2d.org/forum/viewtopic.php?t=115