Crash with compound consisting of many shapes

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Crash with compound consisting of many shapes

Postby Yezide » Tue Mar 24, 2009 6:26 pm

I have had a strange crash when two compound collisions collided, one with 3 shapes and one with 1000. However, I have not been able to replicate this in a controlled environment and am not sure exactly what the cause might be. However the crash went away when I put a max to number of shapes in compound collision (I used 50 as max).
Also note that the crash only happened when the other body with the low shape count had above 1 shape.

Is there a max for shapes in compound collision? What is a reasonable limit?
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: Crash with compound consisting of many shapes

Postby Julio Jerez » Wed Mar 25, 2009 10:06 am

there is not limit as who many bodies can be added to a compoun shape, buf rehg is a limit as to who many compund to compound shape come in contact.
compound collision woh in some sor of a brute for mode,
that is it need the code need to determine what subshape are collinding with each sun shape.
It does that by using a merge the inner loop of a msrege sort,
first is sort both array along the line with worse verianace and then it does the merge to finen teh pontecial colliding pairs, it is in the merge that the bodis limit can be overflow
here is the beginning of the code

Code: Select all
#defione DG_COMPOUND_MAX_SORT_ARRAY 1024

...
      dgInt32 i0;
      dgInt32 j0;
      dgInt32 index;
      dgInt32 count1;
      dgMatrix* collisionMatrixArray1;
      dgConvexCollision** collisionArray1;
      dgCompoundCollision *compoundCollision1;
      struct SortArray
      {
         dgFloat32 m_key;
         dgInt32 m_index;
      };
      SortArray array0[DG_COMPOUND_MAX_SORT_ARRAY];
      SortArray array1[DG_COMPOUND_MAX_SORT_ARRAY];


      _ASSERTE (count < MAX_COMPOUND_SHAPE);
      dgVector sum (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
      dgVector sum2 (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
      for (dgInt32 i = 0; i < count; i ++) {




IT never occured to me peopel will be making compund with mor ethan a taunsand bodies, if this is teh problems I can do tow thongs,
1 make the DG_COMPOUND_MAX_SORT_ARRAY bigger liek 2048 but the will go so far
2 use stack cllocation to alocate teh exact amoudn of memory needed.

This will be hard to reproduces as teh bigger shape many so overrun the stack all the time, but it will evntually do or worse it will simple malfuntion.
can you verify that the bigger shape had more than 1024 shapes
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash with compound consisting of many shapes

Postby Yezide » Wed Mar 25, 2009 11:46 am

I will check this next week and see what I find out.

I am using the compound collision instead of mesh collision (the artist creates the shapes) and was hoping this might speed things up. Instead I am getting slowdowns when using compound collision, but not sure if it might be a fault in my code. Should a compound collision consisting of say 100 shapes generally be faster than mesh, given that the compound tries to be a simple version of the mesh?
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: Crash with compound consisting of many shapes

Postby Julio Jerez » Wed Mar 25, 2009 12:32 pm

a compound collision was no made for that.
if the shape in not muvable, you can use the scene collision.
can you post an image of what you are trying to do?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash with compound consisting of many shapes

Postby Yezide » Thu Mar 26, 2009 3:55 am

Attached image of scene detail with the collision showing.

As can see in the image, I am using the visual geometry to create the collision mesh. This poses some problems:
1) It takes quite a while to compile the mesh collision. It actually takes up over 50% of the map loading time. I know that I could save collison to file, but the loading time will still be a problem during development whenever the map is updated.
2) Some of the collisions get too complex and need to be simplified. For example, there might be a a lot of unneeded details (image not really showing this though) which can cause objects to get stuck or not behave according to gameplay.
3) Need to add special character colliders so that the player can not use every single polygon to jump on (this can causes countless of problems) and also to fill in gaps in the collision.

In our the engine, the maps are made up by many static gameplay pieces (see this video) and the way I tried to solve the above problem was to let most of the pieces have collision shapes. Then when building maps these shapes where combined (just likes meshes are combined now) into several large compound collision.

Now, if compound is not good for this, what should I be using? Would it perhaps be better to have some premade collide meshes (box, cylinder,etc) and then use these to build simplified version (using mesh collison). This will not solve the compile time problem though (not completly at least). Any ideas are welcome!

NOTE: Optimize is off currently. Otherwise the compilation takes even longer.
Attachments
NewtonCollision.jpg
NewtonCollision.jpg (168.75 KiB) Viewed 7396 times
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: Crash with compound consisting of many shapes

Postby Julio Jerez » Thu Mar 26, 2009 10:54 am

so you want to make a level into a compund collision? that will definitlly no work in any away.

Yezide wrote:Now, if compound is not good for this, what should I be using? Would it perhaps be better to have some premade collide meshes (box, cylinder,etc) and then use these to build simplified version (using mesh collison). This will not solve the compile time problem though (not completly at least). Any ideas are welcome!

I mention before there is a new collision shape in newton is the SceneCollision, It is a compund collision for static mesh.
It uses a different spacial organization that is fastr for shapes queries and ray casting since the pieces are static.
It is very eassy to used, and there is a demo in teh SDK teh uses it show how to use it.
It support, and remove, move of queries and you can add all of the oteh promitives, convex or concaves.

for what I can see in the video it is the ideal shape for what you are doing.
It should handle movement of separate shapes althuight the functionality is not ready yet (no one have paid atention so I have not put more effort on it)
but the shape is so fast that you can build and rebuild every time by having two copies and use dowble buffer (wigh waht I was going to use inteenally anyway
one tree is on while othe is rebuild)

could you check shape instead and see how is works?
here is a sample file that show the usage
Code: Select all
ScenePrimitive::ScenePrimitive(const NewtonWorld* nWorld, const char* name, int optimized)
   :OGLModel()
{
   NewtonCollision* scene;

   // create a body and with a scene collision
   scene = NewtonCreateSceneCollision (nWorld);

   // add a collision tree to the scene
   AddCollisionTree(scene, nWorld, name, optimized);

   // add some shapes
   AddPrimitives(scene, nWorld);

   // finish the scene contrution, optimize the collision scene
   NewtonSceneCollisionOptimize (scene);

   // set the world size base on the scene size
   dVector boxP0;
   dVector boxP1;
   // get the position of the aabb of this geometry
   NewtonCollisionCalculateAABB (scene, &m_matrix[0][0], &boxP0.m_x, &boxP1.m_x);

   // add some extra padding the world size
   boxP0.m_x -=  50.0f;
   boxP0.m_y -=  50.0f;
   boxP0.m_z -=  50.0f;
   boxP1.m_x +=  50.0f;
   boxP1.m_y += 500.0f;
   boxP1.m_z +=  50.0f;

   // set the world size
   NewtonSetWorldSize (nWorld, &boxP0.m_x, &boxP1.m_x);

   // set the application level callback
   // create the level body and add it to the world
   m_level = NewtonCreateBody (nWorld, scene);
   NewtonReleaseCollision (nWorld, scene);

   // set the global position of this body
   NewtonBodySetMatrix (m_level, &m_matrix[0][0]);
}


void ScenePrimitive::AddPrimitives(NewtonCollision* scene, const NewtonWorld* nWorld)
{
   NewtonCollision* collision1;
   NewtonCollision* collision2;
   
   dMatrix rotMat (dRollMatrix (0.5f * 3.141592f));
   collision2 = NewtonCreateCylinder (nWorld, 2.0f, 0.5f, &rotMat[0][0]);
   collision1 = NewtonCreateBox (nWorld, 4.0f, 0.5, 4.0f, NULL);

   dMatrix matrix (GetIdentityMatrix());
   for (int y = 0; y < 10; y ++) {
      for (int x = 0; x < 10; x ++) {
         for (int z = 0; z < 10; z ++) {
            NewtonCollision* collision;
            NewtonSceneProxy* sceneProxy;
            matrix.m_posit.m_y = 5.0f + y * 4.0f ;
            matrix.m_posit.m_x = x * 6.0f - 20.0f;
            matrix.m_posit.m_z = z * 6.0f - 24.0f; 
            
            collision = (rand () & 0x010) ? collision1 : collision2;
            sceneProxy = NewtonSceneCollisionCreateProxy (scene, collision);
            NewtonSceneProxySetMatrix (sceneProxy, &matrix[0][0]);
            VisualProxy& shape = m_pieces.Append()->GetInfo();
            shape.m_sceneProxi = sceneProxy;
            shape.m_mesh = new OGLMesh (collision, "smilli.tga", "smilli.tga", "smilli.tga");
            shape.m_matrix = matrix;
         }
      }
   }

   NewtonReleaseCollision (nWorld, collision1);
   NewtonReleaseCollision (nWorld, collision2);
}

Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash with compound consisting of many shapes

Postby Yezide » Thu Mar 26, 2009 11:06 am

Ah yeah you mentioned that before. Will check it out and see how it works.
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: Crash with compound consisting of many shapes

Postby Julio Jerez » Thu Mar 26, 2009 1:34 pm

Yezide wrote:In our the engine, the maps are made up by many static gameplay pieces (see this video) and the way I tried to solve the above problem was to let most of the pieces have collision shapes. Then when building maps these shapes where combined (just likes meshes are combined now) into several large compound collision.


I like that idea, you cna use shaped for editor the world, teh way you can sue the collision for placement and orienetation,
teh you can have a compile of cook fintion teh take teh statk piceds and convere then into a Scen collision ratere tha a big collsio nn tree.
you can add small optimized collision tree to a collsion scene.

I am recomending this Collision objecst because in the future new functionality will use this objcets extensivalliy.
for example static soft collision liek plants, drapes can be added.
Plus this object is also very good for another future feature and have beidng thonkg for a while, sceneless streaming worlds.

BTW the world edotro looks very nice. :mrgreen:
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash with compound consisting of many shapes

Postby Yezide » Tue Apr 28, 2009 12:36 pm

Finally, I am trying out the scene collision now but there is a lot of strangeness with it.

First of all the debug drawing does not draw the shapes correctly.
Here is how it looks when the shapes are put in a compound collision:
http://www.unbirthgame.com/files/newton_compound.jpg
and when I use scene collision it looks like this:
http://www.unbirthgame.com/files/newton_scenecoll.jpg

Secondly, when I do collide with the scene it works, but if I give the object too much power while pressing against a collision in the scene collision, then the app crashes.

Any ideas on any of this?
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 8 guests

cron