Skip to main content
gamedev.net
🔒 Locked

Returning Null?

Started by ACAC Apr 13, 2002 at 11:21 AM 4 replies 200+ views
Original Post
ACAC
ACAC
Ive been trying to write a function that creates a vertex buffer, but it returns NULL when i try to run it. Any ideas why?
  
IDirect3DVertexBuffer8 * MakeVbuffer(int nVertices, CUSTOMVERTEX *Vertices)
{
   IDirect3DVertexBuffer8* tempV; //temp vertexbuffer

   VOID *p_vertices; // pointer to the vbuffer


	
	if( FAILED ( g_pD3DDevice->CreateVertexBuffer( nVertices*sizeof( CUSTOMVERTEX ),
												   0,
												   CUSTOM_VERTEX,
												   D3DPOOL_DEFAULT,
												   &tempV ) ) )
												   return NULL;

	
	if( FAILED ( tempV->Lock(0,nVertices*sizeof( CUSTOMVERTEX ), (BYTE**)&p_vertices, 0 ) ) )
		return NULL;

		memcpy( p_vertices, Vertices, nVertices*sizeof( CUSTOMVERTEX ));

	tempV->Unlock();

	return (tempV);
}
   
Heres where i call it:
  
char * Direct3DInit( )
{
	if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
			return "Error creating D3D Object";

	D3DDISPLAYMODE displayMode;

	//if( FAILED ( g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm) ) )

		 //   return "Error Gettting Adapter Display Mode";


	displayMode.Width=WINDOW_WIDTH; // Set the screen width to the window width

	displayMode.Height=WINDOW_HEIGHT; // Set the screen height to the window height

	displayMode.RefreshRate=0; // Set the refresh rate to default

	displayMode.Format=D3DFMT_R5G6B5; // Set the color format to 565 16 bit


	D3DPRESENT_PARAMETERS d3dpp;
	
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed = FALSE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = displayMode.Format;
	d3dpp.BackBufferWidth = displayMode.Width; // The back buffer width

	d3dpp.BackBufferHeight = displayMode.Height; // The back buffer height


	if( FAILED (g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hwnd, 
										D3DCREATE_SOFTWARE_VERTEXPROCESSING ,
										&d3dpp, &g_pD3DDevice) ) )
			return "Error Creating Device ";

	p_Vertices = Vertices;

	if(MakeVbuffer(3, p_Vertices)== NULL);
			MessageBox(g_hwnd,"NULLRETURNED","BLEH", MB_OK);
			

	return "OK";
}
   
Thanks all! [edited by - ACAC on April 13, 2002 12:23:29 PM]
RoTTer
RoTTer
Hey

I have never used that function (some time I dont mess with DX), but Ill try a wild guess (or whatever its called lol) :

instead :

if( FAILED ( g_pD3DDevice->CreateVertexBuffer( nVertices*sizeof( CUSTOMVERTEX ), 0, CUSTOM_VERTEX, D3DPOOL_DEFAULT, &tempV ) ) )

return NULL;


try :


if( FAILED ( g_pD3DDevice->CreateVertexBuffer( nVertices*sizeof( CUSTOMVERTEX ), 0, CUSTOM_VERTEX, D3DPOOL_DEFAULT, tempV ) ) )

return NULL;



(ie, dont pass the mem value of the tempV pointer, but the mem value of the tempV contents)

I didnt go lookup the CreateVertexBuffer prototype tho to answer this, so Im not sure...


---- edit :

nm, I went lookup the function and found out that you really have to pass a ptr to a ptr, so nm , sorry

anyway, check the return value of the functions and lookup the error, as siaspete said

----

Cya,
-RoTTer

[edited by - RoTTer on April 13, 2002 12:47:55 PM]
ACAC
ACAC
I checked through each, none of the functions fail, it just returns null??? Anyone??
ACAC
ACAC
I found the error all ;-)

its a damn noob one too

I AM A NOOB!!!

Topic Locked

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

Sign in to reply to this topic.