Report any bugs here and we'll post fixes
Moderators: Sascha Willems, Thomas
by hpesoj » Sat Aug 08, 2009 6:53 pm
This is the benchmark code I submitted in the other thread, but altered to use spheres which move outwards. When the spheres roll outside the world bounds, the program crashes. It appears to crash inside the NewtonBodySetForce function within the gravityCallback function. This only happens when using simd commands, and I don't believe this happens with any other primitive shapes, though I am not sure.
- Code: Select all
#include <iostream>
#include <windows.h>
#include <Newton.h>
// High precision timer for Windows.
class Timer
{
public:
//-------------------------------------------------------------------------
Timer() :
mStartTime(),
mTicksPerSecond()
{
QueryPerformanceFrequency(&mTicksPerSecond);
QueryPerformanceCounter(&mStartTime);
}
//-------------------------------------------------------------------------
float getSeconds(bool reset = false)
{
LARGE_INTEGER currentTime;
QueryPerformanceCounter(¤tTime);
float seconds = (float)(
((double)currentTime.QuadPart - (double)mStartTime.QuadPart) /
(double)mTicksPerSecond.QuadPart);
if (reset)
{
QueryPerformanceCounter(&mStartTime);
}
return seconds;
}
private:
LARGE_INTEGER mStartTime;
LARGE_INTEGER mTicksPerSecond;
};
void gravityCallback(const NewtonBody* body, float timestep, int threadIndex)
{
static float force[] = {0.0f, -9.8f, 0.0f};
NewtonBodySetForce(body, force);
}
float sumPosition[3];
int totalSum;
void transformCallback(const NewtonBody* body, const float* matrix, int threadIndex)
{
sumPosition[0] += matrix[12];
sumPosition[1] += matrix[13];
sumPosition[2] += matrix[14];
totalSum++;
}
int main(void)
{
NewtonWorld* world = NewtonCreate(0, 0);
NewtonSetPlatformArchitecture(world, 1);
char arch[256];
NewtonGetPlatformArchitecture(world, arch);
std::cout << "Architecture: " << arch << std::endl;
//--------------------------------------------------
// CHANGE THIS VALUE TO TEST
//--------------------------------------------------
NewtonSetSolverModel(world, 2);
// Create shapes.
NewtonCollision* floorShape = NewtonCreateBox(world, 100.0f, 1.0f, 100.0f, 0, 0);
//NewtonCollision* boxShape = NewtonCreateBox(world, 1.0f, 1.0f, 1.0f, 0, 0);
NewtonCollision* boxShape = NewtonCreateSphere(world, 0.5f, 0.5f, 0.5f, 0, 0);
float boxMass = 1.0f;
float boxInertia[3];
float boxOrigin[3];
NewtonConvexCollisionCalculateInertialMatrix(boxShape, boxInertia, boxOrigin);
// Create floor.
NewtonBody* floor = NewtonCreateBody(world, floorShape);
float floorMatrix[] = {1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, -1.0f, 0.0f, 1.0f};
NewtonBodySetMatrix(floor, floorMatrix);
// Create 10x10x10 stacks of boxes.
float boxMatrix[] = {1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f};
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
for (int z = 0; z < 10; z++)
{
NewtonBody* box = NewtonCreateBody(world, boxShape);
NewtonBodySetMassMatrix(box, boxMass,
boxInertia[0] * boxMass, boxInertia[1] * boxMass, boxInertia[2] * boxMass);
NewtonBodySetAutoSleep(box, 0);
NewtonBodySetForceAndTorqueCallback(box, gravityCallback);
NewtonBodySetTransformCallback(box, transformCallback);
boxMatrix[12] = x * 2.0f * y / 10.0f;
boxMatrix[13] = y * 1.0f;
boxMatrix[14] = z * 2.0f * y / 10.0f;
NewtonBodySetMatrix(box, boxMatrix);
}
}
}
Timer timer;
int iterations = 0;
// Count iterations per second.
while (true)
{
sumPosition[0] = sumPosition[1] = sumPosition[2] = 0.0f;
totalSum = 0;
NewtonUpdate(world, 1.0f / 60.0f);
iterations++;
if (timer.getSeconds() > 1.0f)
{
std::cout << iterations << " iterations in " << timer.getSeconds(true) << std::endl;
std::cout << "Average position: " <<
sumPosition[0] / totalSum << ", " <<
sumPosition[1] / totalSum << ", " <<
sumPosition[2] / totalSum << std::endl;
iterations = 0;
}
}
return 0;
}
-
hpesoj
-
- Posts: 90
- Joined: Sun Jan 09, 2005 4:36 pm
- Location: Cambridge/Bristol, UK
by Julio Jerez » Sat Aug 08, 2009 9:25 pm
wow you found a big bug.
if a body goes out side the world the body is frozen and placed into and inactive list. that part works fine.
however if another body who is still in the world and it is touching the body that is frozen, then the frozen body get activated and the engine try to move it,
but the body is not in the active list, so the code crash trying to get it from the wrong list.
Thank I will put the update with the fix.
I still do not know how I did not see that before, but it is certainly a bug.
In the mean time if you can just move you scene a litle and the bug will go away until I put the new build.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Sun Aug 09, 2009 2:23 pm
Ok Bug fixed you can download beta 2.06
Thank you vey much for the Bug Report
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by hpesoj » Sun Aug 09, 2009 5:03 pm
Cheers Julio.
-
hpesoj
-
- Posts: 90
- Joined: Sun Jan 09, 2005 4:36 pm
- Location: Cambridge/Bristol, UK
Return to Bugs and Fixes
Who is online
Users browsing this forum: No registered users and 9 guests