Skip to main content
GameDev.net gamedev.net
🔒 Locked

Crash

Started by Newbie00 Apr 25, 2004 at 3:53 AM 2 replies 350+ views
Original Post
Newbie00
Newbie00
When I make a call to this function my app crashes. What am I doing wrong?
LPDIRECT3DVERTEXBUFFER8 g_square;

struct my_vertex{
  FLOAT x, y, z, rhw; // The transformed position for the vertex.
  DWORD color;        // The vertex color.
};


my_vertex g_square_vertices[] ={
 { 250.0f,  200.0f, 0.5f, 1.0f, 0x00000000 },
 { 250.0f,  50.0f,  0.5f, 1.0f, 0x00000000 },
 { 400.0f,  200.0f, 0.5f, 1.0f, 0x00000000 },
 { 400.0f,  50.0f,  0.5f, 1.0f, 0x00000000 }
};
 
Here is the function
DrawBox(float Xpos, float Ypos, float width, float height, DWORD Color)
{

	unsigned char *Temp_Vertexbuff;

	//top left of box
	g_square_vertices[0].color = Color;
	g_square_vertices[0].x = Xpos;
	g_square_vertices[0].y = Ypos;
	g_square_vertices[0].z = 20.0f;
	g_square_vertices[0].rhw = 1.0f;

	//bottom left of box
	g_square_vertices[1].color = Color;
	g_square_vertices[1].x = Xpos;
	g_square_vertices[1].y = Ypos + height;
	g_square_vertices[1].z = 20.0f;
	g_square_vertices[1].rhw = 1.0f;

	//top right of box
	g_square_vertices[2].color = Color;
	g_square_vertices[2].x = Xpos + width;
	g_square_vertices[2].y = Ypos;
	g_square_vertices[2].z = 20.0f;
	g_square_vertices[2].rhw = 1.0f;

	//bottom right of box
	g_square_vertices[3].color = Color;
	g_square_vertices[3].x = Xpos + width;
	g_square_vertices[3].y = Ypos + height;
	g_square_vertices[3].z = 20.0f;
	g_square_vertices[3].rhw = 1.0f;

	g_square->Lock(0, 0, &Temp_Vertexbuff, 0);

	memcpy(Temp_Vertexbuff, g_square_vertices, sizeof(g_square_vertices));

	g_square->Unlock();

	pDirect3DDevice->BeingScene();
	pDirect3DDevice->SetVertexShader(D3D8T_CUSTOMVERTEX);

	pDirect3DDevice->SetStreamSource(0, g_square, sizeof(my_vertex));

	pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

	pDirect3DDevice->EndScene();

}
 
Nik02
Nik02
Please show the definition of D3D8T_CUSTOMVERTEX.
Niko Suni
Newbie00
Newbie00
#define D3D8T_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
Nik02
Nik02
Define it as D3DFVF_XYZRHW|D3DFVF_DIFFUSE instead. The RHW portion acknowledges that the geometry data is already in pixel space, and need not be transformed by d3d or the device.

Also, the transformed z coordinates should be in range 0...1. Some devices will clip the geometry off if they exceed that. Although that doesn't generally crash the app, it does make it difficult to see the results

As to why the wrong FVF may crash, is that the device may read or write out of it's memory boundary if the format is specified wrongly.

-Nik

[edited by - Nik02 on April 25, 2004 10:03:23 AM]
Niko Suni

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.