Skip to main content
GameDev.net gamedev.net
🔒 Locked

managed dx IB except

Started by Pseudo Jan 21, 2003 at 8:07 PM 4 replies 750+ views
Original Post
Pseudo
Pseudo
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.
Pseudo
Pseudo
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?
Donavon Keithley
Donavon Keithley
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.
Pseudo
Pseudo
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]
Donavon Keithley
Donavon Keithley
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.

Pseudo
Pseudo
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.