Crash in dgCollisionConvexPolygon

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Crash in dgCollisionConvexPolygon

Postby anothertime12 » Sun Mar 22, 2020 6:52 am

Hi,
I don't have a video etc to demonstrate this but I'm getting an unhandled exception, floating point division by zero on line 569 of dgCollisionConvexPolygon.cpp:

dgVector supportPoint (sphOrigin - relStep.Scale (m_normal.DotProduct(sphOrigin - m_localPoly[0]).GetScalar() / m_normal.DotProduct(relStep).GetScalar()));

This seems to have happened a few times now after I updated to the latest Newton version (I was on 3.1.2), it's fixed a few bugs I was having around substeps and sphere phasing through curved floors sometimes, but now I'm getting this crash.

I don't have a particularly good bug report as I don't have a condition which reproduces this consistently so apologies for that, but I hoped that reporting it may be of some use.
anothertime12
 
Posts: 27
Joined: Tue Nov 27, 2018 11:28 pm

Re: Crash in dgCollisionConvexPolygon

Postby Julio Jerez » Sun Mar 22, 2020 1:00 pm

hi,
yes, I see how it can happen.
relStep is calculated a line 554
Code: Select all
dgVector relStep (relativeVelocity.Scale(dgMax (proxy.m_timestep, dgFloat32 (1.0e-12f))));


as you can see if has provision for the time step to be zero, but does not check if relativeVelocity was already zero. if relativeVelocity is zero then relStep will also be zero vector and that will lead to a zero divide.

I added the early bail out at line 521
please sync and try again.

if happens again can you check in relStep or relativeVelocity are null vectors.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash in dgCollisionConvexPolygon

Postby anothertime12 » Sat Mar 28, 2020 12:00 pm

I now get a crash on dgAABBPolygonSoup.cpp, line 1338: dgFloat32 dist1 = node->BoxIntersect (ray, obbRay, obbAabbInfo, vertexArray);

node seems to be null, (vertexArray is also null).

I uploaded a stack trace here: https://pasteboard.co/J1cJlA3.png
anothertime12
 
Posts: 27
Joined: Tue Nov 27, 2018 11:28 pm

Re: Crash in dgCollisionConvexPolygon

Postby Julio Jerez » Sat Mar 28, 2020 3:01 pm

can I have a repro demo? can you make a demo that link to the dll is possible?

the is no way that node in a collsion tree is NULL, the tree does not ha end nodes.
I see you are trying CCD, and is very possible ther is a bug, but without a repro is had to debug.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash in dgCollisionConvexPolygon

Postby anothertime12 » Sat Mar 28, 2020 6:04 pm

I have played around a bit and now get a crash almost every single time I move something on a collision tree - the crash seems to always be in dgVector on this line: : m_x(*((dgFloat32*)&ix)), m_y(*((dgFloat32*)&iy)), m_z(*((dgFloat32*)&iz)), m_w(*((dgFloat32*)&iw))

Not sure if I can somehow disable ArmNeon - or why it's launching using that on pc? (unless this is just a file mapping issue and the ide is leading me to the wrong file.

I uncommented #define DG_SCALAR_VECTOR_CLASS and rebuilt but the problem remains only now it's:
DG_INLINE dgVector (dgInt32 ix, dgInt32 iy, dgInt32 iz, dgInt32 iw)
:m_x(*((dgFloat32*)&ix)), m_y(*((dgFloat32*)&iy)), m_z(*((dgFloat32*)&iz)), m_w(*((dgFloat32*)&iw))
{
}

in dgVectorScalar.

The console log is also reelentlessly spammed with "function ..\..\..\..\Stuff\newton-dynamics-master\sdk\dgPhysics\dgContact.cpp on file dgContact::EstimateCCD is too slow, fix it"
anothertime12
 
Posts: 27
Joined: Tue Nov 27, 2018 11:28 pm

Re: Crash in dgCollisionConvexPolygon

Postby Julio Jerez » Sat Mar 28, 2020 8:17 pm

The dVectorNeon is not include unless the macro _M_ARM is defined, thsi si something I added very recently for and Arm vector class, it soue no be compiled for x86 build.

like I said, can you make a repro test? is difficult to find oput what is going on by the description you are giving.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash in dgCollisionConvexPolygon

Postby anothertime12 » Sun Mar 29, 2020 8:58 am

OK - spent half the morning on an example.

I've uploaded the data I'm using here: https://gofile.io/?c=u9VkQL

This is not the most incredible code and a few things are done twice but I wanted to replicate what the game is doing a bit as well.


I would like to know why the faceID I pass to NewtonTreeCollisionAddFace is never used/seen again? It's always 0 in the collision callback which means I can't ever use it for anything.

This code crashes for me after about 1 second of running



Code: Select all
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <math.h>

#define _NEWTON_STATIC_LIB
#include "Newton\include\dgNewton\Newton.h"
#pragma comment(lib,"Newton\\lib\\dgCore.lib")
#pragma comment(lib,"Newton\\lib\\dgPhysics.lib")
#pragma comment(lib,"Newton\\lib\\newton.lib")

char* pFileData=NULL;
int iFilePosition=0;
void DeserialiseCollision(void* SerializeHandle,void* Buffer,int Size)
{
   memcpy(Buffer,&pFileData[iFilePosition],Size);
   iFilePosition+=Size;
}

static void ApplyGravity(const NewtonBody* const Body,dFloat timestep,int threadIndex)
{
   float Gravity[]={0.66435254,-17.463728,8.8733788};
   float fMass;float fIXX;float fIYY;float fIZZ;
   NewtonBodyGetMass(Body,&fMass,&fIXX,&fIYY,&fIZZ);
   Gravity[0]*=fMass;Gravity[1]*=fMass;Gravity[2]*=fMass;
   NewtonBodyAddForce(Body,Gravity);
}

void CollisionCallback(const NewtonJoint* ContactJoint,dFloat Timestep,int ThreadIndex)
{
   if(ContactJoint==NULL){return;}
   NewtonBody* pBody1=NewtonJointGetBody0(ContactJoint);
   NewtonBody* pBody2=NewtonJointGetBody1(ContactJoint);
   void* pContact=NewtonContactJointGetFirstContact(ContactJoint);
   while(pContact!=NULL)
   {
      NewtonMaterial* pMaterial=NewtonContactGetMaterial(pContact);
      int iFaceAttribute=NewtonMaterialGetContactFaceAttribute(pMaterial);//doesn't work? always returns 0?
      float fNormalSpeed=NewtonMaterialGetContactNormalSpeed(pMaterial);
      if(fNormalSpeed>5.0f)
      {
         //make a noise
      }
      pContact=NewtonContactJointGetNextContact(ContactJoint,pContact);
   }
}

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrev,LPSTR lpCmdLine,int nShowCmd)
{
   float ZeroVector3[]={0.0f,0.0f,0.0f};
   float IdentityMatrix[]={1.0000000,0.00000000,0.00000000,0.00000000,0.00000000,1.0000000,0.00000000,0.00000000,0.00000000,0.00000000,1.0000000,0.00000000,0.00000000,0.00000000,0.00000000,1.0000000};

   //////////////////////////////////////////////////////////
   //Newton object
   //////////////////////////////////////////////////////////
   NewtonWorld* pNewtonWorld=NewtonCreate();
   //NewtonWorldSetUserData(pNewtonWorld,some pointer to something I use);
   NewtonSetSolverIterations(pNewtonWorld,8);
   NewtonSetNumberOfSubsteps(pNewtonWorld,5);
   NewtonSetThreadsCount(pNewtonWorld,1);

   //////////////////////////////////////////////////////////
   //Materials
   //////////////////////////////////////////////////////////
   int iBallMaterialID=NewtonMaterialCreateGroupID(pNewtonWorld);
   NewtonMaterialSetDefaultElasticity(pNewtonWorld,iBallMaterialID,iBallMaterialID,0.25f);
   NewtonMaterialSetDefaultFriction(pNewtonWorld,iBallMaterialID,iBallMaterialID,2.1f,0.9f);
   NewtonMaterialSetDefaultSoftness(pNewtonWorld,iBallMaterialID,iBallMaterialID,0.25f);
   int iWorldMaterialID=NewtonMaterialCreateGroupID(pNewtonWorld);
   NewtonMaterialSetDefaultElasticity(pNewtonWorld,iWorldMaterialID,iWorldMaterialID,0.25f);
   NewtonMaterialSetDefaultFriction(pNewtonWorld,iWorldMaterialID,iWorldMaterialID,2.1f,0.9f);
   NewtonMaterialSetDefaultSoftness(pNewtonWorld,iWorldMaterialID,iWorldMaterialID,0.25f);

   NewtonMaterialSetCollisionCallback(pNewtonWorld,iBallMaterialID,iWorldMaterialID,NULL,CollisionCallback);

   //////////////////////////////////////////////////////////
   //create the ball
   //////////////////////////////////////////////////////////
   NewtonBody* pBall=NULL;
   {
      NewtonCollision* pCollision=NewtonCreateSphere(pNewtonWorld,0.5f,0,NULL);
      pBall=NewtonCreateDynamicBody(pNewtonWorld,pCollision,IdentityMatrix);
      NewtonBodySetForceAndTorqueCallback(pBall,ApplyGravity);
      NewtonBodySetMassProperties(pBall,1.0f,pCollision);
      NewtonBodySetLinearDamping(pBall,0.01f);
      float Damping[]={0.02f,0.02f,0.02f};
      NewtonBodySetAngularDamping(pBall,Damping);//this lets the ball spin like crazy though
      NewtonDestroyCollision(pCollision);
      NewtonBodySetMaterialGroupID(pBall,iBallMaterialID);
      NewtonBodySetContinuousCollisionMode(pBall,1);
      //NewtonBodySetUserData(pBall,some pointer to something I use);
   }

   //////////////////////////////////////////////////////////
   //create the level - this is normally built as per commented lines, but I'm using serialise here
   //////////////////////////////////////////////////////////
   NewtonBody* pLevel=NULL;
   {
      HANDLE hFile=CreateFileA("Temp.dat",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
      int iFileSize=GetFileSize(hFile,NULL);
      pFileData=new char[iFileSize+1];
      DWORD nRead=0;
      ReadFile(hFile,pFileData,iFileSize,&nRead,NULL);
      NewtonCollision* pCollision=NewtonCreateCollisionFromSerialization(pNewtonWorld,DeserialiseCollision,NULL);
      /*pCollision=NewtonCreateTreeCollision(World,0);
      NewtonTreeCollisionBeginBuild(pCollision);
      for(int I=0;I<IndexCount;I+=3)
      {
         float Triangles[9]={0};
         ..gather triangle data per face
         NewtonTreeCollisionAddFace(pCollision,3,Triangles,3*sizeof(float),1234); <- out of interest - why does 1234 never show up in collision callback, it's always 0?
      }
      NewtonTreeCollisionEndBuild(pCollision,0);*/
      pLevel=NewtonCreateDynamicBody(pNewtonWorld,pCollision,IdentityMatrix);
      NewtonDestroyCollision(pCollision);
      NewtonBodySetMatrix(pLevel,IdentityMatrix);
      NewtonBodySetMaterialGroupID(pLevel,iWorldMaterialID);
   }

   //////////////////////////////////////////////////////////
   //game start logic.. player put into position, world reset etc
   //////////////////////////////////////////////////////////
   float StartPosition[16]={1.0000000,0.00000000,0.00000000,0.00000000,
   0.00000000,1.0000000,0.00000000,0.00000000,
   0.00000000,0.00000000,1.0000000,0.00000000,
   1.4000000,4.9000001,7.6999998,1.0000000};
   NewtonBodySetVelocity(pBall,ZeroVector3);
   NewtonBodySetOmega(pBall,ZeroVector3);
   NewtonBodySetMatrix(pBall,StartPosition);//(1.4f,4.9f,7.7f)
   NewtonInvalidateCache(pNewtonWorld);

   while(true)
   {
      NewtonUpdate(pNewtonWorld,1.0f/60.0f);
      Sleep(10);
      if(GetAsyncKeyState(0x1B)){break;}
   }

   if(pNewtonWorld!=NULL){NewtonDestroyAllBodies(pNewtonWorld);NewtonDestroy(pNewtonWorld);}
   return(0);
}
anothertime12
 
Posts: 27
Joined: Tue Nov 27, 2018 11:28 pm

Re: Crash in dgCollisionConvexPolygon

Postby Julio Jerez » Sun Mar 29, 2020 1:05 pm

al right, I recreate the program.
O can see you are an experience programmer. you set up the serialization they way I expect people would do it, very nice :D

I can now provide the answer the first question.
I would like to know why the faceID I pass to NewtonTreeCollisionAddFace is never used/seen again? It's always 0 in the collision callback which means I can't ever use it for anything.

the function is this.
Code: Select all
unsigned NewtonMaterialGetContactFaceAttribute(const NewtonMaterial* const materialHandle)
{
   TRACE_FUNCTION(__FUNCTION__);
//   dgContactMaterial* const material = (dgContactMaterial*) materialHandle;
dgAssert (0);
//   return (unsigned) ((dgContactMaterial*) materialHandle->m_userId);
return 0;
}


It is fixed now.

the message function ..\..\dgPhysics\dgContact.cpp on file dgContact::EstimateCCD is too slow, fix it
is jus a warning, CCD is expensive because is doing a full collision check.
this is good because remind me that if the distance travel is not too large, then the collsion test can be done only if a abb pre test detect collision. I will do that later.

the question I have is if you are doing 5 sub step. why are you also using continue collision?
teh ball is 0.5 unit in radius, that seems reasonable enough in size the should not need CCD.
I see the gravity is 17.8 I take your units aren't meters. what unit system are you using?

finally, I did am no getting any crash, I have a VS hwo can I load it to some site so that you check if I have it right.

but first try getting later to see if teh fix I made make it better.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash in dgCollisionConvexPolygon

Postby Julio Jerez » Sun Mar 29, 2020 1:38 pm

I try to upload the solution that I created, but I get this error
The upload has failed
Please try again later, Gofile could be in maintenance.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash in dgCollisionConvexPolygon

Postby anothertime12 » Sun Mar 29, 2020 1:43 pm

Fascinating that it works for you - I wonder if I'm building the library incorrectly somehow. I'll have to try and check when I'm home.

The units aren't very empirical at the moment - it's a "what seems correct" as it's more of an "arcade physics" game than a truly accurate simulation.
anothertime12
 
Posts: 27
Joined: Tue Nov 27, 2018 11:28 pm

Re: Crash in dgCollisionConvexPolygon

Postby JernejL » Sun Mar 29, 2020 2:04 pm

Try wetransfer instead of gofile: https://wetransfer.com/
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Crash in dgCollisionConvexPolygon

Postby Julio Jerez » Sun Mar 29, 2020 3:03 pm

I put the project in dropbox.
I use the email that you use to register in the forum. no sure if that will work.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash in dgCollisionConvexPolygon

Postby anothertime12 » Sun Mar 29, 2020 3:22 pm

I don't have a dropbox account.. I'd prefer not to have to sign up to something / give out more details.

I'm just curious what I could be doing wrong when building.. I must confess I find the build process difficult - running cmake gui tools and changing flags etc. I preferred the golden days of precompiled .lib files being downloaded. I use msvc2008 currently.
anothertime12
 
Posts: 27
Joined: Tue Nov 27, 2018 11:28 pm

Re: Crash in dgCollisionConvexPolygon

Postby Julio Jerez » Sun Mar 29, 2020 3:57 pm

But it has been a long time the engine does not support older version of vs, I still have vs2010 and it does not compiled with that version.
Try getting a newer version of vs. they are free now.

The reason older version aren't support is because cpp has changed and we used some of the new features.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash in dgCollisionConvexPolygon

Postby anothertime12 » Sun Mar 29, 2020 5:31 pm

The problem is that we're all set up in the current IDE - it's the paid full version and everything else I have works perfectly.

Is it possible to get precompiled static libraries with header files?
anothertime12
 
Posts: 27
Joined: Tue Nov 27, 2018 11:28 pm

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 8 guests

cron