• Advertisement

Archived

This topic is now archived and is closed to further replies.

managed dx IB except

This topic is 5512 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I created a mesh from an x file and now I want to save the indexbuffer to a file. To do this I need to lock the buffer but I can''t seem to get it working. This is the exception that I get: System.ArgumentNullException: Value cannot be null. Parameter name: elementType at System.Array.CreateInstance(Type elementType, Int32 length) at Microsoft.DirectX.Direct3D.IndexBuffer.Lock(Int32 offsetToLock, Type typeIndex, LockFlags flags, Int32[] ranks) at Microsoft.DirectX.Direct3D.IndexBuffer.Lock(Int32 offsetToLock, LockFlags flags) at SMB3D.Mesh.Save(String file) in c:\dxsdk\samples\c#\direct3d\testmesh\model.cs:line 184 I''m trying to lock it with an offset of 0 and LockFlags.None. I don''t see why it''s not locking, the annoying thing is that I just did this the other day, but I mistakenly saved over the file. Please help me figure out what I''m doing wrong.

Share this post


Link to post
Share on other sites
Advertisement
ok, here is a sample of some of my code:


IndexBuffer ib = new IndexBuffer(device, 1000 * 6, Usage.Dynamic, Pool.Default, false);

Face[] faces = (Face[])ib.Lock(0, LockFlags.None);


the line with Lock on it gives me the exception I was talking about. (and Face is just a struct with three ushorts)

How can I fix this to work?

Share this post


Link to post
Share on other sites
Try calling Mesh.LockIndexBuffer() instead, or you might call the override IndexBuffer.Lock(Int32 offsetToLock, Type typeIndex, LockFlags flags, Int32[] ranks).

IndexBuffer internally holds a Type for the index (usually typeof(short) or typeof(ushort)) and the Lock method you called seems to be assuming it''s non-null. There are a couple of ways that this Type field can be null, so my guess is that this is a bug. But it''s hard to say when the documentation isn''t finished.

At any rate, you want to lock with an explicit type rather than the nonexistent internal one.

Share this post


Link to post
Share on other sites
ok, I want to try that overloaded version of Lock but I don't know what the ranks array is suppose to be. any ideas?

[edited by - Pseudo on January 22, 2003 8:45:14 AM]

Share this post


Link to post
Share on other sites
The ranks parameter lets you set the rank and dimensions of the array that''s returned. For an index buffer, just pass in a single integer representing the number of indices you''re locking. Something like this:

ushort[] indices = (ushort[])ib.Lock(offset, typeof(ushort), lockFlags, numIndices);

You could pass in more than one rank to get back a multidimensional array but I believe there''s a bit of additional overhead since each array index is bounds checked.

Share this post


Link to post
Share on other sites
Thanks for the help, I understand how it works now Donavon.

just in case anyone else has the same problem I did, my final code was like this:

Face[] face = (Face[])indexBuffer.Lock(0,typeof(Face),LockFlags.None, numFace);

that''s the same as Donavons code only using a face structure instead.

Share this post


Link to post
Share on other sites

  • Advertisement