Sign in to follow this  
Bru

internal directx 9 bug?

Recommended Posts

today i tryed to add a very simple note that the game is loading to my game. but apperently it caused a realy odd bug. it happens when i use ID3DXFONT's DrawText function. when i do that, it apperently magicly screws with another function that runs a few lines after that one. i'll show you what happens :
         TextDisplay("Loading...",width/2-20,height/2);
	 Device->EndScene();
         Device->Present(NULL, NULL, NULL, NULL);
	 Device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
         Device->BeginScene();
	 MainPlayer->LoadMesh(Device,"2.x");
	 SecondPlayer->LoadMesh(Device,"Sphere2.x");
	 rock->LoadMesh(Device,"sphere_subd.x");
         rock2->LoadMesh(Device,"city.x");
         rock2->GetVertexList(Device);


inside TextDisplay function is the DrawText function that seems to be directly the cause of the debugger suddenly throwing me an exception when rock2->GetVertexList runs. here is the code for both functions :
void TextDisplay(LPCSTR text,LONG left,LONG top)
{
D3DCOLOR fontColor = D3DCOLOR_ARGB(255,255,0,0);    
RECT rct;
rct.left=left;
rct.right=780;
rct.top=top;
rct.bottom=rct.top+20;
m_font->DrawText(NULL,text , -1, &rct, 0, fontColor );
}


void GetVertexList(LPDIRECT3DDEVICE9 Device)
{
VerticesNum = new D3DXVECTOR3[Mesh->GetNumFaces()*3];//vector3 array containing vertices
IndexNum = new short[Mesh->GetNumFaces()*3];//int array containing indicies
DWORD stride = Mesh->GetNumBytesPerVertex();
BYTE* vbptr = NULL;
BYTE* ibptr = NULL;
D3DXVECTOR3 *pos = VerticesNum;
short *pos2 = IndexNum;
Mesh->LockVertexBuffer(0, (LPVOID*)&vbptr);
for (DWORD i = 0; i < Mesh->GetNumFaces()*3; i++)
{

   memcpy(pos, vbptr, 12);//when i equals 1152, the exception is thrown. and Mesh->GetNumFaces()*3 equals around 1600.
   vbptr += stride; 
   pos++;
}


this is suppoused to be a minor problem, but since i realy cant figure out the connection between these two functions i thought it might be an internal dx failure. has anyone got any clue what's going on?

Share this post


Link to post
Share on other sites
I haven't done this quite a while, but you seem to use an indexed buffer. This means that the number of vertices doesn't have to be the number of faces by 3. Its probably less vertices which are used for multiple faces.

Share this post


Link to post
Share on other sites
Correct. If you're using a triangle list, the number of indices = the number of faces * 3. But the number of vertices is arbitrary.

If you're using a triangle strip, both the number of indices and the number of vertices are arbitrary.

Since you're overwriting arbitrary parts of memory and overrunning the end of the vertex buffer array, it's probably overwritten some important data and is causing it to crash in a seemingly unrelated area.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sc4Freak
Correct. If you're using a triangle list, the number of indices = the number of faces * 3. But the number of vertices is arbitrary.

If you're using a triangle strip, both the number of indices and the number of vertices are arbitrary.

Since you're overwriting arbitrary parts of memory and overrunning the end of the vertex buffer array, it's probably overwritten some important data and is causing it to crash in a seemingly unrelated area.


ehh well,i do use triangle list. but if i try to get the vertices with GetNumVerices in the loop instead of GetNumFaces*3 then i'd find myself not extracting some vertices from the buffer.

i still dont think i understand how running DrawText function screws my GetVertexList function :o

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this