Archived

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

problem with IB pointers array

This topic is 4948 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''ve a poblem ... if I use a IB pointers array like this LPDIRECT3DINDEXBUFFER9 m_pIBChunk[4]; and then I call m_pd3dDevice->CreateIndexBuffer( 32*32*2*3*sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIBChunk, NULL ) where "i" is in the range 0-3, the first call works fine... the others give me an access violation error.... some aidsplease? byez

Share this post


Link to post
Share on other sites
sorry but the forum has eaten the code in the square parenthesis

this is the real code
m_pd3dDevice->CreateIndexBuffer( 32*32*2*3*sizeof(WORD),
D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
D3DPOOL_MANAGED, &m_pIBChunk(i), NULL )

this (with other code) is into a loop
for (int i=0; i<4; i++)
{
....
....
}

but doesn't work ...
If I debug the application, I can see that every loop "i" grows,
but if I try CreateIndexBuffer, I get an access violate error..

[edited by - BlueChip on May 29, 2004 9:20:34 AM]

Share this post


Link to post
Share on other sites
I''ve done this without any problems. Could it have something to do with where you declare your variables? Creating an array of pointers is pretty common in C++ and shouldn''t cause you any problems.

neneboricua

Share this post


Link to post
Share on other sites
Sounds like you''re overstepping some memory boundaries somewhere in your loop. Do you create all of the IBs at once, or create and fill them one at a time?

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

Share this post


Link to post
Share on other sites
This is full code:

WORD *pIndices;
int Index;
int IndexOffset;
int relativeX=0, relativeZ=0;
div_t result;


for ( int i=0; i<4; i++)
{
if( FAILED( m_pd3dDevice->CreateIndexBuffer( 32*32*2*3*sizeof(WORD),
D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
D3DPOOL_MANAGED, &m_pIBChunk[i], NULL ) ) )
{
MessageBox( NULL, "Error: createIB.", "xxx",MB_ICONERROR|MB_OK );
return;
}

if( FAILED( m_pIBChunk[i]->Lock( 0, 0, (void**)&pIndices, 0 ) ) )
{
MessageBox( NULL, "error: lockIB.", "xxx",MB_ICONERROR|MB_OK );
return;
}

// Fill in the index buffer with vertex ID linking the vertex buffer

result = div(i,4);
IndexOffset = 0;
for( z = 0; z < 33; z++ )
{
for( int x = 0; x < 33; x++ )
{
relativeX = (32*(int)result.rem)+x;
relativeZ = (32*(int)result.quot)+z;//offset for the next chunk...


Index = relativeX + ( relativeZ * 33 );
pIndices[IndexOffset] = (WORD)Index;
IndexOffset++;
Index = relativeX +( (relativeZ+1) * 33 );
pIndices[IndexOffset] =(WORD)Index;
IndexOffset++;
Index = relativeX + ( relativeZ * 33 ) +1;
pIndices[IndexOffset] = (WORD)Index;
IndexOffset++;

Index = relativeX +( (relativeZ+1) * 33 );
pIndices[IndexOffset] =(WORD)Index;
IndexOffset++;
Index = relativeX +( (relativeZ+1) * 33 )+ 1;
pIndices[IndexOffset] =(WORD)Index;
IndexOffset++;
Index = relativeX + ( relativeZ * 33 ) +1;
pIndices[IndexOffset] = (WORD)Index;
IndexOffset++;
}
}

m_pIBChunk[i]->Unlock();
}


I've a vertex buffer of 65X65 and do 4 Index Buffer of 33X33 vertex..

quote:

Could it have something to do with where you declare your variables?


I declare my IB variable in a .h file.

quote:

Do you create all of the IBs at once, or create and fill them one at a time?


the 2nd...
I make and fill them one at a time

P.S: This code, with a unique IB or with more distinct IB variables, work fine.... the proble come only if I use LPDIRECT3DINDEXBUFFER9 m_pIBChunk[4];

[edited by - BlueChip on May 31, 2004 10:30:27 AM]

Share this post


Link to post
Share on other sites