Jump to content
  • Advertisement

Archived

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

kapru

Octree troubles

This topic is 5281 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

Im building an octree engine that will load up a .x file mesh and extract all the data and then render it using an Octree for culling. Ive extracted the mesh vertex buffer materials and textures. Now im trying to create and index buffer for each material, but im getting access violations when trying to lock the index buffers here what im doing these are in the header
LPDIRECT3DINDEXBUFFER8 *OctreeIndex;
int *NumIndices;
create the index buffers
OctreeIndex = new LPDIRECT3DINDEXBUFFER8[TableSize];
NumIndices = new int[TableSize];


device->CreateIndexBuffer(65535,
			D3DUSAGE_WRITEONLY,
			D3DFMT_INDEX16,
			D3DPOOL_DEFAULT,
			&OctreeIndex[i]);
and heres the non working lock
unsigned short *ind;

for(int i=0;i<(int)NumMaterials;i++)
{
       OctreeIndex[i]->Lock(0,0,(BYTE**)&ind,0);
}
cant see whats wrong but maybe some one else can thanks

Share this post


Link to post
Share on other sites
Advertisement
Are you checking to see if the creation fails? the access violation is probably occuring because you''re trying to lock a buffer that hasn''t actually been created.

Share this post


Link to post
Share on other sites
Actually, wait - you''re locking in a loop.

Why?

You need to lock, copy data, then unlock.

I''m fairly certain that locking 2 IB''s at the same time will generate the fault.

Share this post


Link to post
Share on other sites
Heres the exact code


for(int i=0;i<(int)NumMaterials;i++)
{
OctreeIndex[i]->Lock(0,0,(BYTE**)&ind,0);
for(int j=(int)AttribTable[i].VertexStart;j<(int)AttribTable[i].VertexStart+(int)AttribTable[i].VertexCount;j++)
{
ind[index++] = TriList[i].PointIndex[0];
ind[index++] = TriList[i].PointIndex[1];
ind[index++] = TriList[i].PointIndex[2];
}
OctreeIndex[i]->Unlock();

}


The denug output says that i =0 swo it crashes on the first lock

[edited by - kapru on June 5, 2004 11:01:10 PM]

Share this post


Link to post
Share on other sites
Are the buffers being created immediately before they''re being filled? Try checking the value (in the debugger...breakpoints are your friend) of the buffer just after it''s created vs. just before it''s used.

Share this post


Link to post
Share on other sites
Yeah the buffers are being created.

I think my problem is converting DWORD''s to int''s

Mesh->GetAttributeTable(AttribTable,&TableSize);

TableSize is a DWORD and so are all the values in AttribTable.

how do i convert a DWORD into an int a simple cast dosnt work

Share this post


Link to post
Share on other sites
A dword is typedef''d as an unsigned short, I believe...therefore it shouldn''t need to be cast (unless you''re trying to cast a pointer to a dword / to a pointer to an int?). Integer promotion should take care of it.

This code:


DWORD dw = 400;
int i = dw;

cout << dw << " = " << i;


should print out the following:

400 = 400.

although you should probably be using an unsigned int anyway, to prevent the compiler from throwing a signed / unsigned warning.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!