Archived

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

TWild

Error creating device

Recommended Posts

I''m getting an assertion error in this function. It appears that my g_pD3DDevice is not pointing to anything after the function call
  
// Create the device interface

	if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
		// error

  
I have "IDirect3DDevice8 *g_pD3DDevice = NULL;" declared in my Globals.h file. Can anyone tell me what I''m doing wrong here? The source to this function Init() is below:
  
BOOL cApp::Init()
{
	
	D3DDISPLAYMODE d3ddm;				// Used to set display mode

	D3DPRESENT_PARAMETERS d3dpp;


	// Obtain interface to Direct3D

	if((g_pD3D = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)
		// error


	
	// Since using window, have windows fill in display mode

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

	
	// Set up presentation method

	
	// Clear out d3dpp structure

	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
	// Set the fields

	d3dpp.Windowed = true;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = d3ddm.Format;  // use same color mode

	d3dpp.EnableAutoDepthStencil = false;

	
	// Create the device interface

	if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
		// error


assert(g_pD3DDevice); // <--- this is the assert that fails


	// Initialize sprite

	if(FAILED(D3DXCreateSprite(g_pD3DDevice, &pSprite)))
		// error



	// Load the texture (page 204)

	
	if(FAILED(D3DXCreateTextureFromFile(g_pD3DDevice, "Texture.bmp", &pTexture)))
		// error


	return true;
  
} // End Init()

  
It is probably something obvious, but I''m learning :D I really appreciate all of the helpful people on this board!

Share this post


Link to post
Share on other sites
Check if it''s possible to create a windowed device on your computer.

first you declare a D3DCAPS8 structure, then you initialize it, then check if "render to window" is supported. you can put it in a little function to return true if it''s supported or false otherwise like so:

  
bool checkDeviceCapabilities(IDirect3D8* d3d)
{
D3DCAPS8 caps;

//all this function does is take the adapter identifier

//Then we give in the devtype

//and we specify hal, because for games this is essential. We cant have a

//game running in REF mode, it would just be too slow


//initialize the caps structure

if(FAILED(d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps)))
return false;

//check if rendering to a window is supported. If it is, ok good

//but if it isn''t then create a fullscree app instead

if(!(caps.Caps2&D3DCAPS2_CANRENDERWINDOWED))
return false;


//if everything went well return TRUE

return true;
}




"I know sometimes I ask stupid questions...but i mean well "
[Triple Buffer-My home]|[SCRIPTaGAME]|[My Old Site]

Share this post


Link to post
Share on other sites