Archived

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

loops and buffers

This topic is 5382 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 create some buffers and stuff that work fine out side of a loop, but as soon as i put them insode a loop it crashes, i dont know why either, should i post the code there is a fair chunk of it?

Share this post


Link to post
Share on other sites
well here is some code, with the creation of the buffers and locking of them, always fails if its in the loop, but as soon as i put it below the loops it passes:


for(int c = -cols/2; c < cols/2; c++)
{
for(int r = -rows/2; r < rows/2; r++)
{
newCell = new CELL;

//Create the vertex buffer from our device.
if(FAILED(Direct3D:D3DDevice->CreateVertexBuffer( cell_vertices.size() * sizeof(TERRAIN_VERTEX),
D3DUSAGE_WRITEONLY, TERRAIN_D3DFVF,
D3DPOOL_DEFAULT, &newCell->pVertexBuffer, 0)))
{
systemLog.WriteLog("Create Vertex Buffer [FAILED]");
return false;
}

//Create the index buffer from our device
if(FAILED(Direct3D:D3DDevice->CreateIndexBuffer( cell_vertices.size() * sizeof(WORD),
D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT,
&newCell->pIndexBuffer, 0)))
{
systemLog.WriteLog("Create Index Buffer [FAILED]");
return false;
}

VERTEX_TERRAIN* pCellVertices;
WORD* pCellIndices;

//lock buffers
newCell->pIndexBuffer->Lock(0, 0, (void**)&pCellIndices, 0);

hr = newCell->pVertexBuffer->Lock(0, 0, (void**)&pCellVertices, 0);
if( FAILED(hr) )
{
systemLog.WriteLog("Lock Terrain Vertex Buffer [FAILED]");
return false;
}

//copy data into buffers (NOT YET DONE)

//unlock buffers
newCell->pIndexBuffer->Unlock();
newCell->pVertexBuffer->Unlock();

worldCells.push_back(*newCell);
}
}

Share this post


Link to post
Share on other sites