Test app for Newton2 bug reproducing [solved]


24-05-2009 22:33:39


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.

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=, 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.)

* 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 - 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?


24-05-2009 23:01:07

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


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?

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);


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

if (!File.Exists(file))
Console.Write("\nFile not found ...\n");
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];

case "Newton_WorldCollisionUpdate": // AND add CHECK command
entry.command = Command.collisionUpdate;
entry.command = Command.checkLastBody;

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));

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));

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

} // 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()
catch (AccessViolationException)
Console.WriteLine("\n\nAccessViolationException at NewtonWorldCollisionUpdate() \nAborted - press Enter to quit...");

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

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("x"); // skip / error


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

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);
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);

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);
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);

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

} // switch

if ((counter % 70) == 0)

} // 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;
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


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.


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