Archived

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

TheGamerHART

Problem with init D3D

Recommended Posts

Hey, i´ve the following code in VC++6
HRESULT InitD3D(HWND hWnd)
{
	lpD3D = Direct3DCreate9(D3D_SDK_VERSION);

	if(lpD3D==NULL)
		return E_FAIL;

	
	D3DPRESENT_PARAMETERS d3dPP;
	d3dPP.Windowed=TRUE;
	d3dPP.SwapEffect=D3DSWAPEFFECT_DISCARD;
	d3dPP.BackBufferFormat=D3DFMT_UNKNOWN;
	d3dPP.BackBufferCount=1;


	lpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
							&d3dPP, &lpD3D_Device);

	if(lpD3D==NULL)
		return E_FAIL;

	
	lpD3D_Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	lpD3D_Device->SetRenderState(D3DRS_LIGHTING, FALSE);

	return S_OK;
}
 
When I start the program it stops at
lpD3D_Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
 
The debug output windows says:
Loaded ''ntdll.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\kernel32.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\user32.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\gdi32.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\advapi32.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\rpcrt4.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\d3d9.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\d3d8thk.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\msvcrt.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\version.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\winmm.dll'', no matching symbolic information found.
Loaded ''C:\WINDOWS\system32\d3d9d.dll'', no matching symbolic information found.
Direct3D9: :====> ENTER: DLLMAIN(00c034f0): Process Attach: 00000668, tid=00000fd8
Direct3D9: (WARN) :Executing processor detection code (benign first-chance exception possible)

Direct3D9: (INFO) :MMX detected

Direct3D9: (INFO) entium Pro CPU features (fcomi, cmov) detected

Direct3D9: (INFO) :dwCPUFamily = 6, dwCPUFeatures = 7

Direct3D9: (INFO) :szCPUString = AuthenticAMD

Direct3D9: :====> EXIT: DLLMAIN(00c034f0): Process Attach: 00000668
Direct3D9: (INFO) :Direct3D9 Debug Runtime selected.
Direct3D9: (ERROR) :BackBufferCount must be less than D3DPRESENT_BACK_BUFFERS_MAX. ValidatePresentParameters fails.
First-chance exception in DirectX.exe: 0xC0000005: Access Violation.
The program ''E:\OLDPROJECTS\DirectXAttempt\Debug\DirectX.exe'' has exited with code 0 (0x0).
 
Whats the problem? Regards TheGamer

Share this post


Link to post
Share on other sites
I think you can´t set d3dPP.BackBufferFormat=D3DFMT_UNKNOWN in windowed mode. Use GetDisplayMode() to obtain the current format of the desktop. Furthermore you should set d3dPP.hDeviceWindow to your target window ( NULL for focus-window).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
now this appears on debugging


Direct3D9: :====> ENTER: DLLMAIN(00c034f0): Process Attach: 00000f0c, tid=00000f04
Direct3D9: (WARN) :Executing processor detection code (benign first-chance exception possible)

Direct3D9: (INFO) :MMX detected

Direct3D9: (INFO) entium Pro CPU features (fcomi, cmov) detected

Direct3D9: (INFO) :dwCPUFamily = 6, dwCPUFeatures = 7

Direct3D9: (INFO) :szCPUString = AuthenticAMD

Direct3D9: :====> EXIT: DLLMAIN(00c034f0): Process Attach: 00000f0c
Direct3D9: (INFO) :Direct3D9 Debug Runtime selected.
First-chance exception in DirectX.exe: 0xC0000005: Access Violation.
The program ''E:\OLDPROJECTS\DirectXAttempt\Debug\DirectX.exe'' has exited with code 0 (0x0).

Share this post


Link to post
Share on other sites
sorry the guy above is me

with this code


D3DPRESENT_PARAMETERS d3dPP;

memset(&d3dPP, 0, sizeof(D3DPRESENT_PARAMETERS));

d3dPP.Windowed=TRUE;
d3dPP.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dPP.BackBufferFormat=DisplayMode.Format;
d3dPP.hDeviceWindow=NULL;

Share this post


Link to post
Share on other sites
d3dPP.hDeviceWindow=NULL; ?????
You should pass this the handle to the window you created.

d3dPP.hDeviceWindow=hWnd;

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
quote:
Original post by UltimaX
d3dPP.hDeviceWindow=NULL; ?????
You should pass this the handle to the window you created.

d3dPP.hDeviceWindow=hWnd;

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"


Don''t think that''s necessary.

.lick

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Now, I''m assuming DirectX.exe is the name of your application. The access violation could be anything, but I get it when I try to dereference a null pointer, deallocated memory, etc. Since the debug doesn''t say anything, it''s probably not a Direct3D problem.

Share this post


Link to post
Share on other sites
Here is the code I use. It works. Maybe comparing it to yours will help you figure out what is wrong.

/// @param pD3d Direct3D object.

/// @param hWnd Window handle.

/// @param ppDevice Where to store the new device.

/// @param zBufferFormat Z-buffer format.

/// @param adapter Which adapter.

/// @param deviceType Device type.

/// @param behavior Behavior (see docs for CreateDevice).


HRESULT CreateD3dWindowedDevice( IDirect3D9 * pD3d,
HWND hWnd,
IDirect3DDevice9 * * ppDevice,
D3DFORMAT zBufferFormat /* = D3DFMT_D24S8 */,
UINT adapter /* = D3DADAPTER_DEFAULT*/,
D3DDEVTYPE deviceType /* = D3DDEVTYPE_HAL*/,
DWORD behavior /* = D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_PUREDEVICE*/
)
{
HRESULT hr;

// Get the format of the desktop


D3DDISPLAYMODE displayMode;

hr = pD3d->GetAdapterDisplayMode( adapter, &displayMode );
if ( FAILED( hr ) )
{
return hr;
}

// Create the d3d device using the desktop format


D3DPRESENT_PARAMETERS present;

ZeroMemory( &present, sizeof( present ) );
present.Windowed = TRUE;
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.BackBufferFormat = displayMode.Format;
present.EnableAutoDepthStencil = ( zBufferFormat != D3DFMT_UNKNOWN );
present.AutoDepthStencilFormat = zBufferFormat;

return pD3d->CreateDevice( adapter, deviceType, hWnd, behavior, &present, ppDevice );
}


[edited by - JohnBolton on July 27, 2003 3:45:46 AM]

Share this post


Link to post
Share on other sites