LockRect() / UnlockRect() problem

hi, i'm writing a D3D game engine in Visual C++ 6.0
I've recently run into a problem with using lightmaps. not the algoritm part is what bothers me, but maybe(?) a API problem. i'm locking a dynamic texture in order to write to it, and then when i unlock it, the whole system crashes

[code]
LPDIRECT3DTEXTURE9 StaticLightmap;
lpDevice->CreateTexture(8, 8,0,D3DUSAGE_DYNAMIC | 3DUSAGE_AUTOGENMIPMAP,
D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&StaticLightmap,NULL);

D3DLOCKED_RECT rect;
StaticLightmap->LockRect(0,&rect,NULL,D3DLOCK_DISCARD);
for (int i=0; i<64; i++) *((DWORD*)(rect.pBits)+i) = 0xFF000000;
StaticLightmap->UnlockRect(0);
[/code]

when UnlockRect() gets called, the system crashes for a few seconds and then trhows me into a 16 color desktop, from which there's nothing else to do but restart windows.
I've run the code step by step and none of the variables are NULL, they all work as they should, but when i get to the UnlockRect(0) statement, it crashes.

If I remove the D3DUSAGE_AUTOGENMIPMAP flag from the creation of the texture, it won't crash any more at the UnlockRect(0) statement, but will crash in exchange when i draw a primitive with this texture on Stage 0.

I really can't see what's going on.... Am I doing something wrong??? can anyone help me ???? i'm really frustrated with this one.

Comments

  • it seems to me, that you may have switched the first 2 arguments of LockRect()....
  • : it seems to me, that you may have switched the first 2 arguments of LockRect()....
    :

    no i didn't switch the arguments: the first argument is the level, which must be 0, because i want to lock the top level of the texture, and the second is the address of the D3DLOCKED_RECT to receive info in.

    but that was long ago, i figured it out eventually. the problem was that despite the texture was dynamic, i shouldn't have used the D3DLOCK_DISCARD flag when locking it. when i removed that flag, everything went just fine.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories