locking dynamic index buffers

Started by
3 comments, last by sordid 18 years, 9 months ago
Hi, I get an error (access violation) when locking a dynamic index buffer. Removing the D3DUSAGE_DYNAMIC flag solves the problem - However, I want to work with a dynamic index buffer. There it is: device->CreateIndexBuffer(sizeof(short)*a, D3DUSAGE_WRITEONLY || D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib[6], NULL); index[6] = new short[a]; short *ind; ib[6]->Lock(0,0,(void**)&ind, D3DLOCK_DISCARD); //ERROR! How can I avoid this error? thx, Chris [Edited by - Christoph on July 4, 2005 6:34:17 PM]
Advertisement
D3DUSAGE_DYNAMIC and D3DPOOL_MANAGED are incompatible and should not be used together. (from the DX Docs)

EDIT: change D3DPOOL_MANAGED to something different, probablY D3DPOOL_DEFAULT.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Quote:Original post by Christoph
D3DUSAGE_WRITEONLY || D3DUSAGE_DYNAMIC


It's probably not even getting created. Use only 1 bar for bitwise OR.

D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC
Quote:Original post by Christoph
device->CreateIndexBuffer(sizeof(short)*a, D3DUSAGE_WRITEONLY || D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib[6], NULL);


That || should be a |.

EDIT: I'm slow :/ . Also, as RhoneRanger says, you need to use D3DPOOL_DEFAULT.
Also be aware now that with the D3DPOOL_DEFAULT setting, you will have to release that index buffer before you call IDirect3DDevice9::Reset(), and reallocate it after the method return. For instance, if you change video mode, resize the backbuffer(s), or for many other reasons you may call ::Reset().

This topic is closed to new replies.

Advertisement