MogreNewt - AccessViolationException - ConvexHull

xlash86

30-11-2008 17:50:44

Hey!

When making this call
Collision cMesh = new MogreNewt.CollisionPrimitives.ConvexHull(mWorld, scnMesh);
I'm getting a AccessViolationException.
A manual-object is attached to the scene-node. The following code is used to create it
private ManualObject CreateConvexManualObject(List<Vector3> hull, ManualObject mo)
{
lock (typeof(CoDMain))
{
if (mo == null)
mo = mSceneManager.CreateManualObject(NameFactory.GetName("MANUAL_OBJECT_"));
else
mo.Clear();

mo.Begin("BaseWhiteNoLight", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
ushort pointIndex = 0;
foreach (
Triangulation.Triangle t
in Triangulation.DelaunayTriangulation2d.Triangulate(hull))
{
mo.Position((float)t.Vertex1.x, (float)t.Vertex1.y, (float)t.Vertex1.z);
mo.Normal(Vector3.UNIT_Z);
mo.Index(pointIndex++);

mo.Position((float)t.Vertex2.x, (float)t.Vertex2.y, (float)t.Vertex2.z);
mo.Normal(Vector3.UNIT_Z);
mo.Index(pointIndex++);

mo.Position((float)t.Vertex3.x, (float)t.Vertex3.y, (float)t.Vertex3.z);
mo.Normal(Vector3.UNIT_Z);
mo.Index(pointIndex++);
}
mo.End();

//mo.ConvertToMesh(NameFactory.GetName("asdasd"));

return mo;
}
}

Any idea what's going wrong?

MfG xlash86

xlash86

30-11-2008 18:39:07

Some update...

After adding some "volume" to the cloud, i get an error (NullReferenceException) one line further, when creating the Body:

float depth = 2;
List<Vector3> cloud = new List<Vector3>();
foreach (Vector3 v3 in mPlayer[playerIndex].WiiMotePlayer.ShapePoints)
{
cloud.Add(new Vector3(v3.x, v3.y, -depth / 2));
cloud.Add(new Vector3(v3.x, v3.y, depth / 2));
}

Collision cMesh = new MogreNewt.CollisionPrimitives.ConvexHull(mWorld, cloud.ToArray());
Body bodyMesh = new Body(mWorld, cMesh);
cMesh.Dispose();

But neither mWorld nor cMesh is null... :?

MfG xlash86

Beauty

12-12-2008 11:34:27

I also noticed this problem.
If you add a SceneNode with a ManualObject then you get a crash.
If I remember right the first attached object (of a SceneNode) will be refered to Newton. (look to the code if you need to know)
There is no check for ManualObjects in the MogreNewt code. This should be added to further versions.


My way of solution: I refered all vertices (points) of the ManualObject to Newton.
Vertices are type Vector3[].
MogreNewt.CollisionPrimitives.ConvexHull colHull
= new MogreNewt.CollisionPrimitives.ConvexHull(nWorld, vertices);



An other possible solution:
Convert the ManualObject to a Mesh and attach this to the SceneNode.
Use the function ManualObject::convertToMesh for it:
www.ogre3d.org/docs/api/html/classOgre_ ... 7f02b07efe

If you do it by this way than it would be nice if you publish a short example code:
Create a ManualObject, convert it to a Mesh, create a SceneNode, attach Mesh, create a ConvexHull