Re: Simple Example of Mesh.Sphere

From: Achim Domma (Procoders) (
Date: 10/17/04

Date: Sun, 17 Oct 2004 20:56:46 +0200

Ok, I'm one step further. I have to clone the mesh and set the colors of
the vertices. But doing that I have another problem. Here is my code:

Mesh tmpSphere = Mesh.Sphere(device,1,10,10);
mesh = tmpSphere.Clone(0, CustomVertex.PositionNormalColored.Format,

VertexBuffer vb = mesh.VertexBuffer;
CustomVertex.PositionNormalColored[] vert =
     (CustomVertex.PositionNormalColored[])vb.Lock(0,0,0); <-- Error

for(int i=0; i<50; i++)
     vert[i].Color = System.Drawing.Color.Red.ToArgb();

The call to Lock throws an exception:

Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object.
    at System.Object.FastGetExistingType()
    at System.Object.GetType()
    at Microsoft.DirectX.DXHelp.GetObjectSize(Object objectSize)
    at Microsoft.DirectX.Direct3D.VertexBuffer.Lock(Int32 offsetToLock,
Type typeVertex, LockFlags flags, Int32[] ranks)
    at Microsoft.DirectX.Direct3D.VertexBuffer.Lock(Int32 offsetToLock,
LockFlags flags)

Any idea what's going wrong?