Test app for Newton2 bug reproducing [solved]

Beauty

24-05-2009 22:33:39

Hi,

I found a bug in a new function of Newton 2.
In special situations there is a freeze by calling World.CollisionUpdate().

Now I wrote a test application which reproduces the problem.
The developer of the Newton physics library wants fix the problem,
BUT: My test application doesn't work on his computer.

He doesn't know Mogre and has no C# experience.

update:
All problems are solved and the bug is fixed!


I still get these error when I launch form VS

An unhandled exception of type 'System.BadImageFormatException' occurred in Microsoft.VisualStudio.HostingProcess.Utilities.dll

Additional information: Could not load file or assembly 'Mogre, Version=0.2.2.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.


and if I try to debug the DLL when I launch the code it crash before it even initlize the Newton DLL.


I never saw a program thar crashes before it even get to the first line,
when I press F10 the code goes for about two or three minutes and then give me that error message.



I never had a BadImageFormatException. In the forum I found that it happens with 64bit Windows.
But I'm not shure if this is the problem.
Is there somebody who have Windows 64bit and can try to run/compile my application?
For just running use start.bat.

http://beauty-of-darkness.de/pub/Collis ... -05-25.rar
(You will see console outputs and after ~15 seconds there should be a freeze. Then just kill the application.)


Info:
* I have Win XP (32 bit)
* My test application was created by Visual Studio 2008
* it uses OpenGL (to avoid problems by missing DirectX depencies)
* The Mogre.dll was build by VS 2005 (I suppose - it's Mogre 0.2.2.0 - related to Ogre 1.4.3)


In the MogreSDK I found no 64 bit version and I never worked with a 64 bit system.
Is there a 64 bit version needed to run?

smiley80

24-05-2009 23:01:07

Set the platform in "Properties->Build" to x86. This will force 32 bit mode.

Beauty

25-05-2009 15:40:10

Now after some trouble the author of Newton could run my test application.
First problem solved :)


But he can't debug his linked Newton library, because the application is C# and his library C++.
Does anybody has an idea how to do?

update:
debugging problem solved


I see tha teh applycation run a couple of loop until it hangs,

but now I have a bigger problem, I can not debug it because C# do not let the application to be debugged

when I step in debug from the app I can only step on c# files
if I try to debugg form the Newton project, it does not let me debug
and even if I try to attack to the demo get this the C# and protected,

I remember long time ago another engine that is in c# and have a problems and I could never debug.
do you know how to do so that I can debug it, ... I can not set a break point I can no debug it.



Or an other way - to port my test application to C++.
My C++ knowledge is bad, so I can't do it (or would need very long time).
Some commands/classes are not available at C++ and I don't know alternatives.

Maybe somebody else wants to port the code?

(Don't be confused if you open the linked project (of first post). There unnessesary methods, which don't need to be port. The reason: my test application is just a quick hack of another test application.)

Newton 2 has the new function NewtonWorldCollisionUpdate(), but in some cases there is a deadlog.
The appliations loads commands from a logfile (attached) and redo the needed steps to repoduce a bug.

Theese methods are needed:


World m_World;
MaterialID material1;
MaterialID material2;
System.Globalization.CultureInfo en; // english culture
List<LogEntry> logList;



public void Init_Newton()
{
// Newton initialization
m_World = new World();
m_World.SetWorldSize(new Vector3(0, 0, 0), new Vector3(10000, 1000, 10000));

} // Init_Newton()




public void StartNewtonTest()
{
Console.BufferHeight = 1000;
Console.BufferWidth = 120;
Console.WindowWidth = 120;
material1 = new MaterialID(m_World);
material2 = new MaterialID(m_World);
MaterialPair mp = new MaterialPair(m_World, material1, material2);
LoadLogfile();
Playback();

}




void LoadLogfile()
{
String file = "positionOrientation.txt";
this.logList = new List<LogEntry>();

if (!File.Exists(file))
{
Console.Write("\nFile not found ...\n");
}
else
{
StreamReader sr = new StreamReader(file);
String line, command;
String[] values;

while (!sr.EndOfStream)
{
line = sr.ReadLine();
values = Regex.Split(line, "\t");
LogEntry entry = new LogEntry();

command = values[0];
switch (command)
{
case "Newton_SetPositionOrientation":
entry.command = Command.posOri;
entry.pos = new Vector3(Convert.ToSingle(values[1], en), Convert.ToSingle(values[2], en), Convert.ToSingle(values[3], en));
entry.ori = new Quaternion(Convert.ToSingle(values[4], en), Convert.ToSingle(values[5], en), Convert.ToSingle(values[6],en), Convert.ToSingle(values[7], en));
entry.obName = values[8];
this.logList.Add(entry);
break;


case "Newton_WorldCollisionUpdate": // AND add CHECK command
entry.command = Command.collisionUpdate;
this.logList.Add(entry);
entry.command = Command.checkLastBody;
this.logList.Add(entry);
break;


case "Newton_NewObject_AABB":
entry.command = Command.newBox;
entry.obName = values[1];
entry.AABB = new Vector3(Convert.ToSingle(values[2], en), Convert.ToSingle(values[3], en), Convert.ToSingle(values[4], en));
this.logList.Add(entry);
break;


case "Newton_NewObject_Vertices":
entry.command = Command.newHull;
entry.obName = values[1];
entry.vertices = new List<Vector3>();
// parse values
String[] verticeStrList = Regex.Split(values[2], "__");
foreach (String str in verticeStrList)
{
String[] v = Regex.Split(str, ";");
Vector3 vertex = new Vector3(Convert.ToSingle(v[0], en), Convert.ToSingle(v[1], en), Convert.ToSingle(v[2], en));
entry.vertices.Add(vertex);
}
this.logList.Add(entry);
break;


default:
if (command != "")
Console.WriteLine("Unknown command in logfile: " + command);
// skip (e.g. empty line)
break;

} // case

}

sr.Close(); // close file


}
} // LoadLogfile()



void Playback()
{
String lastObject = "";
Dictionary<String, Body> bodyList = new Dictionary<string, Body>(); // name + body
Int32 counter = 1;

foreach (LogEntry entry in logList)
{
switch (entry.command)
{
case Command.collisionUpdate:
Console.Write("u"); // before update

// AccessViolationException count: 4
// StackTrace:
// at NewtonCollisionUpdate(NewtonWorld* )
// at MogreNewt.World.CollisionUpdate()
try
{
m_World.CollisionUpdate();
}
catch (AccessViolationException)
{
Console.WriteLine("\n\nAccessViolationException at NewtonWorldCollisionUpdate() \nAborted - press Enter to quit...");
Console.ReadLine();
}

if (Console.CursorLeft > 0)
Console.CursorLeft -= 1; // do overwerite
Console.Write("U"); // after update
counter++;
break;


case Command.posOri:
if (bodyList.ContainsKey(entry.obName) && (entry.pos != null) && (entry.ori != null))
{
bodyList[entry.obName].SetPositionOrientation(entry.pos, entry.ori);
lastObject = entry.obName;
Console.Write(".");
counter++;
}
else
Console.Write("x"); // skip / error

break;


case Command.checkLastBody:
if (bodyList.ContainsKey(lastObject))
{
Console.Write("c"); // check
Boolean contact = CheckForCollision(bodyList[lastObject]);
if (contact)
{
if (Console.CursorLeft > 0)
Console.CursorLeft -= 1; // do overwerite
Console.Write("C"); // if Collision found
}
}
break;


case Command.newBox:
Collision col = new MogreNewt.CollisionPrimitives.Box(
m_World, entry.AABB, new Quaternion(0, Vector3.UNIT_Y));
Body body = new Body(m_World, col);
col.Dispose();
body.SetMassMatrix(1.0f, new Vector3(1.0f, 1.0f, 1.0f));
// body.UserData = new DataType.NewtBodyProperty(targetNode.Name, isSublobe);
// body.SetPositionOrientation(targetNode.WorldPosition, targetNode.WorldOrientation);
body.MaterialGroupID = material1;
body.SetPositionOrientation(Vector3.ZERO, new Quaternion(0, Vector3.UNIT_Y)); // just a default
bodyList.Add(entry.obName, body);
Console.WriteLine("Added box: " + entry.obName);
break;


case Command.newHull:
Collision col2 = new MogreNewt.CollisionPrimitives.ConvexHull(
m_World, entry.vertices.ToArray(), new Quaternion(0, Vector3.UNIT_Y), 0.01f);
Body body2 = new Body(m_World, col2);
col2.Dispose();
body2.SetMassMatrix(1.0f, new Vector3(1.0f, 1.0f, 1.0f));
body2.MaterialGroupID = material2;
body2.SetPositionOrientation(Vector3.ZERO, new Quaternion(0, Vector3.UNIT_Y)); // just a default
bodyList.Add(entry.obName, body2);
Console.WriteLine("Added convexHull: " + entry.obName);
break;


default:
throw new Exception("Unknown command: " + entry.command.ToString());
//break;

} // switch

if ((counter % 70) == 0)
{
Console.WriteLine();
counter++;
}

} // foreach

} //Playback()






Boolean CheckForCollision(Body body)
{
//Console.Write("c"); // check

Body otherBody;
Boolean contact = false;

foreach (ContactJoint joint in body.ContactJoints)
{
if (joint.Body0 == body)
otherBody = joint.Body1;
else
otherBody = joint.Body0;
contact = true;
}

return contact;
} // CheckForCollision()





struct LogEntry
{
public Command command;
public Vector3 pos;
public Quaternion ori;
public String obName;
public Vector3 AABB;
public List<Vector3> vertices;
}


enum Command
{
posOri,
collisionUpdate,
newBox,
newHull,
checkLastBody
}

Beauty

25-05-2009 16:47:27

Ok, now the author of Newton found a way how to debug his linked library.
So DON'T PORT the application. There is not anymore a need.

Beauty

25-05-2009 22:17:33

Now the bug seems to be fixed :D
I made several tests and everything is fine.
And for small vs. huge objects a contact still will be detected.

I I found it, I had to go to a serius of hooks setting security and debug options.
I do not know what flag did it by now I can debug.
I still can not step for the Newton SDK but it is OK, i can debug like this.

any way I found the bug.

you have very huge bodies that are colliding with small bodies,
the bug happens when build the Mincosky hull for such pair.
the resulting hull is soo flat that 32 bit floats lose presistion.
I have a fallback precedure but even the fallback fail.

I am fixing it now. stand by