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

Octree troubles

Started by kapru Jun 5, 2004 at 9:24 AM 7 replies 450+ views
Original Post
kapru
kapru
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
Etnu
Etnu
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.
---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
Direct
Direct
Yeah, what Etnu said.
David Clifton
kapru
kapru
Yeah i am checking if it gets created so thats not the problem
Etnu
Etnu
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.
---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
kapru
kapru
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]
Etnu
Etnu
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.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
kapru
kapru
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
Etnu
Etnu
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.
---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

Topic Locked

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

Sign in to reply to this topic.