NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.13

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.13

Postby Windrider » Tue Jan 12, 2016 3:46 am

Hello,
here is how I build my collision tree:

Code: Select all
NewtonCollision* CLPhysicEntity::BuildPhysicStaticBody(CTVMesh* Mesh, NewtonWorld* World) {
   //  Build the physics mesh and colision tree   
   float Temp;
   int i, vec1, vec2, vec3, Group, color, NbrFaces, NbrVertex;
   NbrFaces = Mesh->GetTriangleCount();
   NbrVertex = Mesh->GetVertexCount();
   char* name = Mesh->GetMeshName();
   std::cout << "Creating " << name << " physic body" << "- Faces/Vertex: " << NbrFaces << "/" << NbrVertex << std::endl;
   sVERTEX *sVertex = new sVERTEX[NbrFaces * 3];
   for (int j = 0; j<NbrFaces * 3; j++)
   {
      sVertex[j].x = 0;    // Initialize all elements to zero.
      sVertex[j].y = 0;
      sVertex[j].z = 0;
   }
   NewtonCollision* MeshCollision = NewtonCreateTreeCollision(World, 666);
   NewtonTreeCollisionBeginBuild(MeshCollision);

   for (i = 0; i < NbrFaces * 3; i = i + 3)
   {
      Mesh->GetTriangleInfo(i / 3, &vec1, &vec2, &vec3, &Group);
      Mesh->GetVertex(vec1, &sVertex[i].x, &sVertex[i].y, &sVertex[i].z, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &color);
      Mesh->GetVertex(vec2, &sVertex[i + 1].x, &sVertex[i + 1].y, &sVertex[i + 1].z, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &color);
      Mesh->GetVertex(vec3, &sVertex[i + 2].x, &sVertex[i + 2].y, &sVertex[i + 2].z, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &color);
      NewtonTreeCollisionAddFace(MeshCollision, 3, &sVertex[i].x, sizeof(sVERTEX), 0);
   }
   // Finalize the collision tree build
   NewtonTreeCollisionEndBuild(MeshCollision, 1);
   delete[] sVertex;  // When done, free memory pointed to by sVertex.
   sVertex = NULL;     // Clear a to prevent using invalid memory reference.
   return(MeshCollision);
}


My application was doing fine with a 3.13 dll.
I changed my application to now use static lib with the latest newton code and I now have a few of my meshes that are giving me a debug assertion failed:
dgArray "i >=0"
I tried to debug that for a while now but cannot find what is wrong.

CallStack:
Graphysic.dll!dgArray<int>::operator[](int i) Line 94 C++
Graphysic.dll!dgPolygonSoupDatabaseBuilder::dgPolygonSoupDatabaseBuilder(const dgPolygonSoupDatabaseBuilder & source) Line 155 C++
Graphysic.dll!dgPolygonSoupDatabaseBuilder::End(bool optimize) Line 471 C++
Graphysic.dll!dgCollisionBVH::EndBuild(int optimize) Line 95 C++
Graphysic.dll!NewtonTreeCollisionEndBuild(const NewtonCollision * const treeCollision, int optimize) Line 3475 C++
Graphysic.dll!CLPhysicEntity::BuildPhysicStaticBody(CTVMesh * Mesh, NewtonWorld * World) Line 155 C++



All my other meshes are ok (all blender exported to directX format), and the rest of my physic application works fine as well, only a few meshes are giving me this error...


Any idea? I'm out of resources.... :S
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Sweenie » Tue Jan 12, 2016 4:16 am

Try without optimization and see if that makes any difference...

// Finalize the collision tree build
NewtonTreeCollisionEndBuild(MeshCollision, 0);
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 4:45 am

Thx for your quick reply but sadly not....

Unhandled exception at 0x008C3FD4 (msvcr120d.dll) in Win32Tester.exe: 0xC0000005: Access violation writing location 0x00825000.

breaking at:

Code: Select all
void dgMemoryAllocator::FreeLow (void* const retPtr)
{
   dgMemoryInfo* const info = ((dgMemoryInfo*) (retPtr)) - 1;
   dgAssert (info->m_allocator == this);

   dgAtomicExchangeAndAdd (&m_memoryUsed, -info->m_size);

#ifdef _DEBUG
-->   memset (retPtr, 0, info->m_workingSize);

Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 11:00 am

Here is the call stack as well if it can help:

msvcr120d.dll!memset(unsigned char * dst, unsigned char value, unsigned long count) Line 87 Unknown
> Graphysic.dll!dgMemoryAllocator::FreeLow(void * const retPtr) Line 222 C++
Graphysic.dll!dgFreeStack(void * const ptr) Line 492 C++
Graphysic.dll!dgStackBase::~dgStackBase() Line 45 C++
Graphysic.dll!dgStack<dgTriplex>::~dgStack<dgTriplex>() Line 77 C++
Graphysic.dll!dgAABBPolygonSoup::CalculateAdjacendy() Line 569 C++
Graphysic.dll!dgCollisionBVH::EndBuild(int optimize) Line 98 C++
Graphysic.dll!NewtonTreeCollisionEndBuild(const NewtonCollision * const treeCollision, int optimize) Line 3475 C++
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Julio Jerez » Tue Jan 12, 2016 11:21 am

Oh it seems some of you meshes are polygonal soups lot of not conneted faces.
in function void dgAABBPolygonSoup::CalculateAdjacendy ()
line 521 make the temp array tree time larger, that will collect the maximum number of possible edges.
Code: Select all
      dgStack<dgInt32> indexArray (normalCount + 256);
      dgInt32 newNormalCount = dgVertexListToIndexList (&pool[0].m_x, sizeof (dgTriplex), sizeof (dgTriplex), 0, normalCount, &indexArray[0], dgFloat32 (1.0e-6f));

      dgInt32 oldCount = GetVertexCount();
      dgTriplex* const vertexArray = (dgTriplex*) dgMallocStack (sizeof (dgTriplex) * (oldCount + newNormalCount + 256));


see if that work and I commit the fix.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 1:20 pm

Humm... nope, same result

Is there something I can modify in the way I build my mesh or the collision tree?

I don't really understand what would be different from some of my mesh then others since I build them all the same way.

Do I need to add something after the "NewtonTreeCollisionAddFace" in my BuildPhysicStaticBody function?
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Julio Jerez » Tue Jan 12, 2016 1:42 pm

is true that some change were made for 3.13 and 3.14 basically in 3.13 and 3.14 triangle that do not have a share edge now the edge point to a dummy normal, rather than to an invalid normal. This causes the final mesh to a larger array of normal, but the run time collision code is simpler and behave better. It is possible that I have a bug on calculate the array size but I have never seem it failing.

since this bug happen when building the mesh, the only way for me to test it is with the actual mesh
can you provide me we a sample that I can test?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 1:52 pm

Your help being really appreciated, I can surely do that! :)

Do you want the DirectX format? It is a text file so I can copy it here.

Or do you need me to save this as a newton mesh?
Or you need a application sample zipped and sent by email?
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 2:26 pm

Just in case, here is the .X file:

Code: Select all
xof 0303txt 0032

Frame Root {
  FrameTransformMatrix {
     1.000000, 0.000000, 0.000000, 0.000000,
     0.000000,-0.000000, 1.000000, 0.000000,
     0.000000, 1.000000, 0.000000, 0.000000,
     0.000000, 0.000000, 0.000000, 1.000000;;
  }
  Frame Cube {
    FrameTransformMatrix {
       1.000000, 0.000000, 0.000000, 0.000000,
       0.000000, 1.000000, 0.000000, 0.000000,
       0.000000, 0.000000, 0.071093, 0.000000,
       2.895028, 4.252898,-0.024318, 1.000000;;
    }
    Mesh { // Cube mesh
      18;
      -1.000000;-0.250724;-1.013631;,
      -1.000000;-1.000000;-1.013631;,
      -1.500865;-1.500865;-0.248382;,
      -1.500865;-0.250724;-0.248382;,
       1.097913;-0.250724;-0.864034;,
       1.000000;-0.250724;-1.013631;,
      -1.500865;-0.250724; 0.221120;,
      -1.000000;-0.250724; 0.986369;,
       1.000000;-0.250724; 0.986369;,
       1.097913;-0.250724; 0.836773;,
       1.000000;-1.000000;-1.013631;,
       1.097913;-1.500865;-0.248382;,
       1.097913;-1.097913;-0.864034;,
      -1.500865;-1.500865; 0.221120;,
      -1.000000;-1.000000; 0.986369;,
       1.000000;-1.000000; 0.986369;,
       1.097913;-1.097913; 0.836773;,
       1.097913;-1.500865; 0.221120;;
      12;
      4;3,2,1,0;,
      8;9,8,7,6,3,0,5,4;,
      4;0,1,10,5;,
      5;12,10,1,2,11;,
      4;6,13,2,3;,
      4;4,5,10,12;,
      4;7,14,13,6;,
      4;8,15,14,7;,
      4;16,15,8,9;,
      4;11,2,13,17;,
      5;17,13,14,15,16;,
      6;9,4,12,11,17,16;;
      MeshNormals { // Cube normals
        12;
        -0.836714; 0.000000;-0.547640;,
         0.000000; 1.000000;-0.000000;,
         0.000000; 0.000000;-1.000000;,
        -0.000000;-0.836714;-0.547640;,
        -1.000000; 0.000000;-0.000000;,
         0.836714; 0.000000;-0.547640;,
        -0.836714; 0.000000; 0.547640;,
         0.000000; 0.000000; 1.000000;,
         0.836714; 0.000000; 0.547640;,
         0.000000;-1.000000; 0.000000;,
        -0.000000;-0.836714; 0.547640;,
         1.000000; 0.000000; 0.000000;;
        12;
        4;0,0,0,0;,
        8;1,1,1,1,1,1,1,1;,
        4;2,2,2,2;,
        5;3,3,3,3,3;,
        4;4,4,4,4;,
        4;5,5,5,5;,
        4;6,6,6,6;,
        4;7,7,7,7;,
        4;8,8,8,8;,
        4;9,9,9,9;,
        5;10,10,10,10,10;,
        6;11,11,11,11,11,11;;
      } // End of Cube normals
      MeshMaterialList { // Cube material list
        1;
        12;
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0;;
        Material Material_003 {
           0.640000; 0.354960; 0.004687; 1.000000;;
           96.078431;
           0.500000; 0.500000; 0.500000;;
           0.000000; 0.000000; 0.000000;;
        }
      } // End of Cube material list
    } // End of Cube mesh
  } // End of Cube
} // End of Root
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 2:44 pm

Hum, very weird!! but your explanation made me look closer to the difference between my .X files that works or not and I just tested the fact that if UV coordinates are not in the .X file, it crashes but if works fine if they are exported in the .X file.
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Julio Jerez » Tue Jan 12, 2016 2:48 pm

that text file is simple enough, I can check that. the function you are using to make the collision is? NewtonCollision* CLPhysicEntity::BuildPhysicStaticBody
also I see the mesh is made of variable size polygons, that might be part of the bug. I will check
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Julio Jerez » Tue Jan 12, 2016 2:54 pm

Windrider wrote:that works or not and I just tested the fact that if UV coordinates are not in the .X file, it crashes but if works fine if they are exported in the .X file.

the file you list reduce to this.

Code: Select all
    Mesh { // Cube mesh
      18;
      -1.000000;-0.250724;-1.013631;,
      -1.000000;-1.000000;-1.013631;,
      -1.500865;-1.500865;-0.248382;,
      -1.500865;-0.250724;-0.248382;,
       1.097913;-0.250724;-0.864034;,
       1.000000;-0.250724;-1.013631;,
      -1.500865;-0.250724; 0.221120;,
      -1.000000;-0.250724; 0.986369;,
       1.000000;-0.250724; 0.986369;,
       1.097913;-0.250724; 0.836773;,
       1.000000;-1.000000;-1.013631;,
       1.097913;-1.500865;-0.248382;,
       1.097913;-1.097913;-0.864034;,
      -1.500865;-1.500865; 0.221120;,
      -1.000000;-1.000000; 0.986369;,
       1.000000;-1.000000; 0.986369;,
       1.097913;-1.097913; 0.836773;,
       1.097913;-1.500865; 0.221120;;
      12;
      4;3,2,1,0;,
      8;9,8,7,6,3,0,5,4;,
      4;0,1,10,5;,
      5;12,10,1,2,11;,
      4;6,13,2,3;,
      4;4,5,10,12;,
      4;7,14,13,6;,
      4;8,15,14,7;,
      4;16,15,8,9;,
      4;11,2,13,17;,
      5;17,13,14,15,16;,
      6;9,4,12,11,17,16;;

will that mesh cause the crash?

also the exporting uv cause face to be disjoints, by the engine do take care of that. my guess is that the calculation of the intermediate buffer size if wrong when the are variable size polygons
this should be easy to fix. It just need to make sure the mesh reproduce the bug.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 3:11 pm

I trace the code a bit and (NormalCount) is always 0 so the application never goes in the corrected code you've provided.
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 3:12 pm

Here is the another example:

Working mesh:
Code: Select all
xof 0303txt 0032

Frame Root {
  FrameTransformMatrix {
     1.000000, 0.000000, 0.000000, 0.000000,
     0.000000,-0.000000, 1.000000, 0.000000,
     0.000000, 1.000000, 0.000000, 0.000000,
     0.000000, 0.000000, 0.000000, 1.000000;;
  }
  Frame Rotator {
    FrameTransformMatrix {
       1.000000, 0.000000, 0.000000, 0.000000,
       0.000000, 1.000000, 0.000000, 0.000000,
       0.000000, 0.000000, 1.000000, 0.000000,
       2.640593,-2.627665, 0.516712, 1.000000;;
    }
    Mesh { // Rotator mesh
      24;
      -0.383556;-0.383556; 0.383556;,
      -0.383556; 0.383557; 0.383556;,
      -0.383556; 0.383557;-0.383556;,
      -0.383556;-0.383556;-0.383556;,
      -0.383556; 0.383557; 0.383556;,
       0.383556; 0.383557; 0.383556;,
       0.383556; 0.383557;-0.383556;,
      -0.383556; 0.383557;-0.383556;,
       0.383556; 0.383557; 0.383556;,
       0.383556;-0.383556; 0.383556;,
       0.383556;-0.383556;-0.383556;,
       0.383556; 0.383557;-0.383556;,
       0.383556;-0.383556; 0.383556;,
      -0.383556;-0.383556; 0.383556;,
      -0.383556;-0.383556;-0.383556;,
       0.383556;-0.383556;-0.383556;,
      -0.383556;-0.383556;-0.383556;,
      -0.383556; 0.383557;-0.383556;,
       0.383556; 0.383557;-0.383556;,
       0.383556;-0.383556;-0.383556;,
       0.383556;-0.383556; 0.383556;,
       0.383556; 0.383557; 0.383556;,
      -0.383556; 0.383557; 0.383556;,
      -0.383556;-0.383556; 0.383556;;
      6;
      4;3,2,1,0;,
      4;7,6,5,4;,
      4;11,10,9,8;,
      4;15,14,13,12;,
      4;19,18,17,16;,
      4;23,22,21,20;;
      MeshNormals { // Rotator normals
        6;
        -1.000000; 0.000000; 0.000000;,
         0.000000; 1.000000;-0.000000;,
         1.000000; 0.000000;-0.000000;,
         0.000000;-1.000000; 0.000000;,
        -0.000000; 0.000000;-1.000000;,
        -0.000000; 0.000000; 1.000000;;
        6;
        4;0,0,0,0;,
        4;1,1,1,1;,
        4;2,2,2,2;,
        4;3,3,3,3;,
        4;4,4,4,4;,
        4;5,5,5,5;;
      } // End of Rotator normals
      MeshTextureCoords { // Rotator UV coordinates
        24;
         0.006056;-0.000410;,
         1.001747;-0.000410;,
         1.001747; 0.995281;,
         0.006056; 0.995281;,
         0.003763; 0.004570;,
         0.999453; 0.004570;,
         0.999453; 1.000261;,
         0.003763; 1.000261;,
         1.003008; 0.001230;,
         0.007318; 0.001230;,
         0.007318; 0.996920;,
         1.003008; 0.996920;,
         0.998539; 0.005136;,
         0.002849; 0.005136;,
         0.002849; 1.000826;,
         0.998539; 1.000826;,
         0.000663; 0.995886;,
         0.000663; 0.000195;,
         0.996353; 0.000195;,
         0.996353; 0.995886;,
         0.998539; 0.999626;,
         0.998539; 0.003935;,
         0.002849; 0.003935;,
         0.002849; 0.999626;;
      } // End of Rotator UV coordinates
      MeshMaterialList { // Rotator material list
        1;
        6;
        0,
        0,
        0,
        0,
        0,
        0;;
        Material TwoWay {
           0.640000; 0.640000; 0.640000; 1.000000;;
           96.078431;
           0.500000; 0.500000; 0.500000;;
           0.000000; 0.000000; 0.000000;;
          TextureFilename {"twoway.jpg";}
        }
      } // End of Rotator material list
    } // End of Rotator mesh
  } // End of Rotator
} // End of Root


not working mesh:

Code: Select all

xof 0303txt 0032

Frame Root {
  FrameTransformMatrix {
     1.000000, 0.000000, 0.000000, 0.000000,
     0.000000,-0.000000, 1.000000, 0.000000,
     0.000000, 1.000000, 0.000000, 0.000000,
     0.000000, 0.000000, 0.000000, 1.000000;;
  }
  Frame Rotator {
    FrameTransformMatrix {
       1.000000, 0.000000, 0.000000, 0.000000,
       0.000000, 1.000000, 0.000000, 0.000000,
       0.000000, 0.000000, 1.000000, 0.000000,
       2.640593,-2.627665, 0.516712, 1.000000;;
    }
    Mesh { // Rotator mesh
      24;
      -0.383556;-0.383556; 0.383556;,
      -0.383556; 0.383557; 0.383556;,
      -0.383556; 0.383557;-0.383556;,
      -0.383556;-0.383556;-0.383556;,
      -0.383556; 0.383557; 0.383556;,
       0.383556; 0.383557; 0.383556;,
       0.383556; 0.383557;-0.383556;,
      -0.383556; 0.383557;-0.383556;,
       0.383556; 0.383557; 0.383556;,
       0.383556;-0.383556; 0.383556;,
       0.383556;-0.383556;-0.383556;,
       0.383556; 0.383557;-0.383556;,
       0.383556;-0.383556; 0.383556;,
      -0.383556;-0.383556; 0.383556;,
      -0.383556;-0.383556;-0.383556;,
       0.383556;-0.383556;-0.383556;,
      -0.383556;-0.383556;-0.383556;,
      -0.383556; 0.383557;-0.383556;,
       0.383556; 0.383557;-0.383556;,
       0.383556;-0.383556;-0.383556;,
       0.383556;-0.383556; 0.383556;,
       0.383556; 0.383557; 0.383556;,
      -0.383556; 0.383557; 0.383556;,
      -0.383556;-0.383556; 0.383556;;
      6;
      4;3,2,1,0;,
      4;7,6,5,4;,
      4;11,10,9,8;,
      4;15,14,13,12;,
      4;19,18,17,16;,
      4;23,22,21,20;;
      MeshNormals { // Rotator normals
        6;
        -1.000000; 0.000000; 0.000000;,
         0.000000; 1.000000;-0.000000;,
         1.000000; 0.000000;-0.000000;,
         0.000000;-1.000000; 0.000000;,
        -0.000000; 0.000000;-1.000000;,
        -0.000000; 0.000000; 1.000000;;
        6;
        4;0,0,0,0;,
        4;1,1,1,1;,
        4;2,2,2,2;,
        4;3,3,3,3;,
        4;4,4,4,4;,
        4;5,5,5,5;;
      } // End of Rotator normals
      MeshMaterialList { // Rotator material list
        1;
        6;
        0,
        0,
        0,
        0,
        0,
        0;;
        Material TwoWay {
           0.640000; 0.640000; 0.640000; 1.000000;;
           96.078431;
           0.500000; 0.500000; 0.500000;;
           0.000000; 0.000000; 0.000000;;
          TextureFilename {"twoway.jpg";}
        }
      } // End of Rotator material list
    } // End of Rotator mesh
  } // End of Rotator
} // End of Root



same mesh with the UV coordinates removed
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Re: NewtonTreeCollisionEndBuild - Crash with 3.14 but not 3.

Postby Windrider » Tue Jan 12, 2016 3:18 pm

I am confused because I do not use any UV information to build the collision tree.

My mesh is loaded with my TV3D engine, and then I simply get all vertex info to build the collision tree face by face.

I'm not using the Newton Mesh as I thought it would be unnecessary to build a mesh from a mesh to then build the collision.
And it usually worked... if I use NewtonDebug on my working mesh, All is fine and draw correctly.

Thanks again! let me know if I can assist you with any test!
Windrider
 
Posts: 22
Joined: Mon Nov 02, 2015 2:34 pm

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 7 guests

cron