I am learning Newton at the moment. It all works well for as long as the world
does not contain too many bodies, but segfaults beyond a certain limit.
For me, that limit is ~40k non-penetrating bodies, or ~5k penetrating bodies.
The segfault happens in `dgBroadPhase::UpdateContactsBroadPhaseEnd` or
`dgBroadPhase::ImproveFitness`, respectively.
Am I doing something wrong? Is there a limit to the number of bodies one
can/should have in the world?
The code below reproduces this for me (Intel CPU, 16GB Ram, Ubuntu 16.04, Debug
build), where `spacing` is either 10.0f or 0.1f.
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "Newton.h"
int main (int argc, const char * argv[])
{
// Specify the number of bodies to create, and their spacing.
const int numBodies = 100000;
const dFloat spacing = 10.0f;
NewtonWorld* const world = NewtonCreate();
std::vector<NewtonCollision*> cshapes(numBodies);
std::vector<NewtonBody*> bodies(numBodies);
std::vector<dFloat*> TMs(numBodies);
for (int ii=0; ii < numBodies; ii++) {
// Create neutral transform matrix for current body.
dFloat const ref_TM[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0 ,0, 1
};
TMs.at(ii) = new dFloat[16];
for (int jj=0; jj < 16; jj++) TMs.at(ii)[jj] = ref_TM[jj];
// Update the position to enforce inter-body spacing.
TMs.at(ii)[13] = ii * spacing;
// Create dynamic body from collision shape.
cshapes.at(ii) = NewtonCreateBox(world, 1, 1, 1, 0, NULL);
bodies.at(ii) = NewtonCreateDynamicBody(world, cshapes.at(ii), TMs.at(ii));
NewtonBodySetMassMatrix(bodies.at(ii), 1.0f, 1, 1, 1);
}
// Segfaults here.
NewtonUpdate(world, 1.0f/60);
NewtonDestroyAllBodies(world);
NewtonDestroy(world);
return 0;
}