Archived

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

ByteMe95

THIS BUG IS DRIVING ME NUTS!!!

Recommended Posts

This isnt going to be easy to explain in detail but I will try. My game was going smoothly for the past few weeks, and I just added a new effect. This is a 2D game using Direct3D 8. So my background is an 800x600 image that gets chopped up into 256x256 textures and tehn gets rendered to the screen. That has always worked. Now I added a new effect where certain blocks get shattered. I do this by creating a new vertexbuffer for the effect and rendering as necessary. The problem is this (EXTREMELY STRANGE, ive been trying to crack it for about 2 hours now): After the FIRST time the effect shows up, which causes the vertex buffer to be locked/unlocked for the effect every frame (efficient for this purpose), ater the frist lock/unlock, the background image''s FIRST upper left texture disappears!!! It just doesnt render, but the rest of the background does. Even stranger: The background gets drawn BEFORE the effect. Even stranger: The effect particles have their own texture to them, and I can almost see small pieces of the shatter effect using the texture that is missing from the background!! But the vast majority of the pieces use the texture they''re supposed to. I know this is a very strange and specific problem which might not find an answer here but im open to any suggestions. Thanks ByteMe95::~ByteMe95() My S(h)ite

Share this post


Link to post
Share on other sites
causes:

1. you are trashing your vertex buffers by reading past bounds that you have not locked.
2. you are locking the buffer mulitple times per frame, you CANT do that. you are allowed to lock/write/unlock once to a vertex buffer section per BeginScene/EndScene.
3. check your zbuffer, possible things are getting screwy
4. check return codes for errors that may be ahppening
5. dynamic vertex buffers should be created with the DYNAMIC flag and locked with WRITEONLY. you should not read from a vertex buffer, nor do you ever need to. furthermore look into the d3d8 sdk samples on how to correctly render particles.

explain more in depth with some psudeo code exactly what your effect does.

Share this post


Link to post
Share on other sites
Hey.
Well I create the VB with:

  
App.pDirect3DDevice->CreateVertexBuffer(18 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC,D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &ShatterVB);


I tried D3DUSAGE_WRITEONLY there also, made no difference

I lock like so:
if(ShatterVB->Lock(0, 0, (BYTE**)&pVertices, D3DLOCK_DISCARD)!=D3D_OK) error;

I check for errors, there are none.
You said to lock with WRITEONLY but there is no lock option for that?

I also checked and it only locks/unlocks once per frame.

Here is a quick pic of the effect wtih the error:


There should be 6 triangles (green. The blue textured triangle is using the texture from what should be the background texture.
It''s even joining vertices that should not be joined!! Those should be 2 separate triangles, the 2 green ones, and the blue wrong textured one is coming out of nowhere.

Here si basically how my effect works, I have this struct:

  
typedef struct _shatterpiece
{
CUSTOMVERTEX V[3];
float xv, yv;
float zRot;
int Alpha;
} shatterpiece;


And I have shatterpiece Pieces[6]; per square
I then fill up Pieces (each piece represents 1 triangle) with appropriate values.

Then to render I do something like:

  
if(ShatterVB->Lock(0, 0, (BYTE**)&pVertices, D3DLOCK_DISCARD)!=D3D_OK)
return false;

for(int i=0; i<6; i++)
{
pVertices[i*3] = Pieces[i].V[0]; pVertices[i*3+1] = Pieces[i].V[1];
pVertices[i*3+2] = Pieces[i].V[2];
}

if(ShatterVB->Unlock()!=D3D_OK)
return false;

App.pDirect3DDevice->SetTexture(0, Texture);
App.pDirect3DDevice->SetStreamSource(0, ShatterVB, sizeof(CUSTOMVERTEX));
App.pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 6);



I cant find the problem at all!!!

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
oops, thats D3DLOCK_NOOVERWRITE
have you tried hardcoded values in the buffer? since you dont show how you generate your vertices, the problem could be there. also check your culling it could cause some weirdness. check the vertex order and make sure its correct for your culling. i also noticed you are not setting your vertexshader.
SetVertexShader(D3DFVF_CUSTOMVERTEX) is required before you call DrawPrimitive(). otherwise things will not work correctly.

Share this post


Link to post
Share on other sites
I fixed the bug. I still dont know what would cause the error, but I created the vertexbuffer in the contructor. I moved that to a function that gets called when the effect is needed and it worked!

It was still probably the strangest error I''ve ever encountered
thanks for your help


ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites