Well, maybe i do have some memory corruption issues, but posting anyway...
I made a heightfield to compare performance with my meshes.
I have just the heightmap in the scene, plus the car in the middle.
I can drive for a second, then the crash happens every time.
The height field is pretty flat, just some smooth high frequency noise. But it's high resolution, 20 cm edge length.
- Code: Select all
static ndBodyKinematic* BuildHeightFieldTerrain (ndWorld& world, const ndMatrix& xform)
{
constexpr ndInt32 D_TERRAIN_WIDTH = 256;
constexpr ndInt32 D_TERRAIN_HEIGHT = 256;
constexpr ndFloat32 D_TERRAIN_GRID_SIZE = 0.2f;
constexpr ndFloat32 D_TERRAIN_ELEVATION_SCALE = 1.f;
ndArray<ndFloat32> heightfield(D_TERRAIN_WIDTH * D_TERRAIN_HEIGHT);
heightfield.SetCount(D_TERRAIN_WIDTH * D_TERRAIN_HEIGHT);
ndFloat32 minHeight = ndFloat32(1.0e10f);
ndFloat32 maxHight = ndFloat32(-1.0e10f);
for (ndInt32 y = 0; y < D_TERRAIN_HEIGHT; y++)
{
for (ndInt32 x = 0; x < D_TERRAIN_WIDTH; x++)
{
ndVector p (x * D_TERRAIN_GRID_SIZE, 0.f, y * D_TERRAIN_GRID_SIZE, 0.f);
ndFloat32 noiseVal = PROCEDURAL::C33::ValueNoise3D((float*)&p);
heightfield[y * D_TERRAIN_WIDTH + x] = noiseVal;
minHeight = ndMin(minHeight, noiseVal);
maxHight = ndMax(maxHight, noiseVal);
}
}
ndFloat32 highScale = D_TERRAIN_ELEVATION_SCALE;
ndFloat32 scale = ndFloat32(2.0f) / (maxHight - minHeight);
for (ndInt32 i = 0; i < heightfield.GetCapacity(); ++i)
{
ndFloat32 y = heightfield[i];
y = scale * (y - minHeight) - ndFloat32(1.0f);
heightfield[i] *= highScale;
}
// create the height field collision and rigid body
ndShapeInstance heighfieldInstance(
new ndShapeHeightfield(D_TERRAIN_WIDTH, D_TERRAIN_WIDTH,
ndShapeHeightfield::m_invertedDiagonals,
D_TERRAIN_GRID_SIZE, D_TERRAIN_GRID_SIZE));
ndShapeHeightfield* const shape = heighfieldInstance.GetShape()->GetAsShapeHeightfield();
ndArray<ndReal>& hightMap = shape->GetElevationMap();
dAssert(hightMap.GetCount() == heightfield.GetCount());
for (int i = 0; i < heightfield.GetCount(); ++i)
{
ndFloat32 high = heightfield[i];
hightMap[i] = ndReal(high);
}
shape->UpdateElevationMapAabb();
ndBodyDynamic* const body = new ndBodyDynamic();
body->SetNotifyCallback(new BodyNotify);
body->SetMatrix(xform);
body->SetCollisionShape(heighfieldInstance);
world.AddBody(body);
return body;
}
Edit:
Tried to change elevation scale to 0(flat) and 10. But still the same crash.