• Advertisement
Sign in to follow this  

Can not create Direct3D device

This topic is 3328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am playing with the source code from the book Beginning Game Programming 2nd. I am working on chapter 5 that first starts with initializing DirectX (D3D), my code compiles and links fine but when it runs it is setting the d3ddev (d3d device) to null and then going into the error if statement and not running. My video card is directX capable and I have the direct X 9 sdk install and linked in Visual C++ 2008. Here is the code: Thanks for any help. // Beginning Game Programming // Chapter 5 // Direct3D_Fullscreen program //header files to include #include <d3d9.h> #include <time.h> //application title #define APPTITLE "Direct3D_Fullscreen" //macros to read the keyboard asynchronously #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) //screen resolution #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 //forward declarations LRESULT WINAPI WinProc(HWND,UINT,WPARAM,LPARAM); ATOM MyRegisterClass(HINSTANCE); int Game_Init(HWND); void Game_Run(HWND); void Game_End(HWND); //Direct3D objects LPDIRECT3D9 d3d = NULL; LPDIRECT3DDEVICE9 d3ddev = NULL; //window event callback function LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_DESTROY: Game_End(hWnd); PostQuitMessage(0); return 0; } return DefWindowProc( hWnd, msg, wParam, lParam ); } //helper function to set up the window properties ATOM MyRegisterClass(HINSTANCE hInstance) { //create the window class structure WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); //fill the struct with info wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = APPTITLE; wc.hIconSm = NULL; //set up the window with the class info return RegisterClassEx(&wc); } //entry point for a Windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // declare variables MSG msg; // register the class MyRegisterClass(hInstance); // initialize application //note--got rid of initinstance HWND hWnd; //create a new window hWnd = CreateWindow( APPTITLE, //window class APPTITLE, //title bar WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP, //window style CW_USEDEFAULT, //x position of window CW_USEDEFAULT, //y position of window SCREEN_WIDTH, //width of the window SCREEN_HEIGHT, //height of the window NULL, //parent window NULL, //menu hInstance, //application instance NULL); //window parameters //was there an error creating the window? if (!hWnd) return FALSE; //display the window ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); //initialize the game if (!Game_Init(hWnd)) return 0; // main message loop int done = 0; while (!done) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { //look for quit message if (msg.message == WM_QUIT) done = 1; //decode and pass messages on to WndProc TranslateMessage(&msg); DispatchMessage(&msg); } else //process game loop (else prevents running after window is closed) Game_Run(hWnd); } return msg.wParam; } int Game_Init(HWND hwnd) { //initialize Direct3D d3d = Direct3DCreate9(D3D_SDK_VERSION); if (d3d == NULL) { MessageBox(hwnd, "Error initializing Direct3D", "Error", MB_OK); return 0; } //set Direct3D presentation parameters D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = SCREEN_WIDTH; d3dpp.BackBufferHeight = SCREEN_HEIGHT; d3dpp.hDeviceWindow = hwnd; //create Direct3D device d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); //if (d3ddev == NULL) //{ // MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK); //return 0; //} //set random number seed srand(time(NULL)); //return okay return 1; } void Game_Run(HWND hwnd) { //make sure the Direct3D device is valid if (d3ddev == NULL) return; //clear the backbuffer to black d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,0), 1.0f, 0); //start rendering if (d3ddev->BeginScene()) { //do something //stop rendering d3ddev->EndScene(); } //display the back buffer on the screen d3ddev->Present(NULL, NULL, NULL, NULL); //check for escape key (to exit program) if (KEY_DOWN(VK_ESCAPE)) PostMessage(hwnd, WM_DESTROY, 0, 0); } void Game_End(HWND hwnd) { //release the Direct3D device if (d3ddev != NULL) d3ddev->Release(); //release the Direct3D object if (d3d != NULL) d3d->Release(); }

Share this post


Link to post
Share on other sites
Advertisement
Solved: I changed D3DDEVTYPE_DEFAULT to D3DDEVTYPE_REF and did not use a hardware device but a software-emulated device it is working now

Share this post


Link to post
Share on other sites
Quote:
Original post by size_J
Solved: I changed D3DDEVTYPE_DEFAULT to D3DDEVTYPE_REF and did not use a hardware device but a software-emulated device it is working now


You shouldn't have to do this. The Ref device is implemented in software, and it's really for testing only. What's worse is that your program probably won't work on most computers if you use Ref. Try changing it to D3DDEVTYPE_HAL, and in the flags use D3DCREATE_HARDWARE_VERTEXPROCESSING and D3DCREATE_PUREDEVICE.

Also, call d3d->GetDeviceCaps() to make sure your video card can support whatever you need. I think all modern video cards should be able to support what I indicated above, though.

Quote:
Original post by computergeek101234
Sorry to interrupt, but...I also have a problem here. The "d3d" variable always returns null, and I can't figure out why. Can anyone help?


Post your code and I'll take a look.

Share this post


Link to post
Share on other sites
Okay. It's the same as the first post by size_j. I'm also running through the tutorials in that book. Also, I'm sorry. It is the "d3ddev" variable that always returns null, not the "d3d". I know that I have the right harware, because I can play games like roller coaster tycoon and seaworld tycoon which use directx 9. Thanks in advance!

Share this post


Link to post
Share on other sites
Quote:
Original post by computergeek101234
Okay. It's the same as the first post by size_j. I'm also running through the tutorials in that book. Also, I'm sorry. It is the "d3ddev" variable that always returns null, not the "d3d". I know that I have the right harware, because I can play games like roller coaster tycoon and seaworld tycoon which use directx 9. Thanks in advance!
Well, the same answer applies: What do the debug runtimes say?

There's nothing I can see wrong with the code that would be caused by anything other than D3D being disabled somehow.

EDIT:
Quote:
Original post by computergeek101234
Okay. It's the same as the first post by size_j. I'm also running through the tutorials in that book. Also, I'm sorry. It is the "d3ddev" variable that always returns null, not the "d3d". I know that I have the right harware, because I can play games like roller coaster tycoon and seaworld tycoon which use directx 9. Thanks in advance!
Roller Coaster Tycoon uses DirectDraw, not D3D. I've never played Seaworld Tycoon, but from the screenshots it looks like the same engine - so DirectDraw.

Can you run any D3D apps or SDK samples?

Share this post


Link to post
Share on other sites
The Debug info is:

Direct3D9: (INFO) :Direct3D9 Debug Runtime selected.
Direct3D9: :Device doesn't support mip-maps
Direct3D9: (ERROR) :HAL Disabled: Device doesn't support texturing
Direct3D9: :Device doesn't support mip-maps
Direct3D9: (ERROR) :HAL Disabled: Device doesn't support texturing
Direct3D9: (ERROR) :HAL Disabled: Device doesn't support texturing
D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO
Direct3D9: :Device doesn't support mip-maps

I can also run the samples

Share this post


Link to post
Share on other sites
Quote:
Original post by size_J
The Debug info is:

Direct3D9: (INFO) :Direct3D9 Debug Runtime selected.
Direct3D9: :Device doesn't support mip-maps
Direct3D9: (ERROR) :HAL Disabled: Device doesn't support texturing
Direct3D9: :Device doesn't support mip-maps
Direct3D9: (ERROR) :HAL Disabled: Device doesn't support texturing
Direct3D9: (ERROR) :HAL Disabled: Device doesn't support texturing
D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO
Direct3D9: :Device doesn't support mip-maps
Looks like one or more of:
1. You don't have drivers installed.
2. You've disabled hardware acceleration from the DirectX Control Panel
3. You have an extremely old card that only does 2D (An old Matrox card for instance).

Share this post


Link to post
Share on other sites
Okay. Here it is.

Direct3D9: (ERROR) :Invalid value for BackBufferFormat. ValidatePresentParameters fails.

I have the back buffer format set to D3DFMT_UNKNOWN. I already tried changing it to D3DFMT_X8R8G8B8. Does that help?

Share this post


Link to post
Share on other sites
Quote:
Original post by computergeek101234
Okay. Here it is.

Direct3D9: (ERROR) :Invalid value for BackBufferFormat. ValidatePresentParameters fails.

I have the back buffer format set to D3DFMT_UNKNOWN. I already tried changing it to D3DFMT_X8R8G8B8. Does that help?
D3DFMT_UNKNOWN is only valid for windowed mode, where it means "Use the desktop format". In fullscreen mode you need to set a valid format. D3DFMT_X8R8G8B8 should be fine if your graphics card can do 32-bit (Which it should). Alternatively, use IDirect3D9::GetAdapterDisplayMode to get the desktop format, and use that.

Share this post


Link to post
Share on other sites
Sorry it took me so long to see this:

Quote:
Original post by Evil SteveCan you run any D3D apps or SDK samples?


The answer is no. I've tried millions of times to run the sdk apps. As far as D3D apps, I don't know.

Also, I don't get the "Direct3D9: (ERROR) :Invalid value for BackBufferFormat. ValidatePresentParameters fails." error anymore. But the program still shutdowns down and tells me "Error creating Direct3D device".

Share this post


Link to post
Share on other sites
Quote:
Original post by computergeek101234
The answer is no. I've tried millions of times to run the sdk apps. As far as D3D apps, I don't know.

Also, I don't get the "Direct3D9: (ERROR) :Invalid value for BackBufferFormat. ValidatePresentParameters fails." error anymore. But the program still shutdowns down and tells me "Error creating Direct3D device".
What's the new debug output?

It still sounds to me like missing drivers, or are running in safe mode / via remote desktop. Have you tried getting the latest drivers for your graphics card?

Share this post


Link to post
Share on other sites
Okay. Here is the new debug output:

'd3d_windowed.exe': Loaded 'C:\Documents and Settings\Kenneth\My Documents\Visual Studio 2008\Projects\d3d_windowed\Debug\d3d_windowed.exe', Symbols loaded.
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\d3d9.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\d3d8thk.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\version.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\winmm.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcr90d.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\lpk.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\usp10.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\msctf.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\ole32.dll'
'd3d_windowed.exe': Loaded 'C:\Program Files\MarkAny\ContentSafer\MaCSProHook.dll', Binary was not built with debug information.
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\winspool.drv'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
Starting.......'d3d_windowed.exe': Loaded 'C:\WINDOWS\system32\Hook.dll', Binary was not built with debug information.
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\mapi32.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\d3d9d.dll'
'd3d_windowed.exe': Loaded 'C:\WINDOWS\system32\d3dx9d_30.dll'
Direct3D9: :====> ENTER: DLLMAIN(00c9d6e0): Process Attach: 0000071c, tid=00000248
Direct3D9: :====> EXIT: DLLMAIN(00c9d6e0): Process Attach: 0000071c
Direct3D9: (INFO) :Direct3D9 Debug Runtime selected.
Direct3D9: (WARN) :driver set D3DDEVCAPS_TEXTURENONLOCALVIDMEM w/o DDCAPS2_NONLOCALVIDMEM:turning off D3DDEVCAPS_TEXTURENONLOCALVIDMEM
D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO
Direct3D9: (WARN) :driver set D3DDEVCAPS_TEXTURENONLOCALVIDMEM w/o DDCAPS2_NONLOCALVIDMEM:turning off D3DDEVCAPS_TEXTURENONLOCALVIDMEM
Direct3D9: :====> ENTER: DLLMAIN(00c9d6e0): Process Detach 0000071c, tid=00000248
Direct3D9: (INFO) :MemFini!
Direct3D9: (WARN) :Memory still allocated! Alloc count = 3
Direct3D9: (WARN) :Current Process (pid) = 0000071c
Direct3D9: (WARN) :Memory Address: 00536ee0 lAllocID=1 dwSize=000047f8, (pid=0000071c)
Direct3D9: (WARN) : Stack Back Trace
Direct3D9: (ERROR) : [0] : Address 00C9D4CB
Direct3D9: (ERROR) : [1] : Address 00C9D59B
Direct3D9: (ERROR) : [2] : Address 00C9D440
Direct3D9: (ERROR) : [3] : Address 00C91D44
Direct3D9: (ERROR) : [4] : Address 4FDFAF2E
Direct3D9: (ERROR) : [5] : Address 004118D4
Direct3D9: (ERROR) : [6] : Address 00411702
Direct3D9: (ERROR) : [7] : Address 00412C58
Direct3D9: (ERROR) : [8] : Address 004129BF
Direct3D9: (ERROR) : [9] : Address 7C816D4F
Direct3D9: (ERROR) : [10] : Address 00000000
Direct3D9: (ERROR) : [11] : Address 00000000
Direct3D9: (ERROR) : [12] : Address 00000000
Direct3D9: (ERROR) : [13] : Address 00000000
Direct3D9: (ERROR) : [14] : Address 00000000
Direct3D9: (ERROR) : [15] : Address 00000000
Direct3D9: (WARN) :Memory Address: 008429c8 lAllocID=8 dwSize=00000360, (pid=0000071c)
Direct3D9: (WARN) : Stack Back Trace
Direct3D9: (ERROR) : [0] : Address 00C94064
Direct3D9: (ERROR) : [1] : Address 00C94E4F
Direct3D9: (ERROR) : [2] : Address 00C95588
Direct3D9: (ERROR) : [3] : Address 00C91D65
Direct3D9: (ERROR) : [4] : Address 4FDFAF2E
Direct3D9: (ERROR) : [5] : Address 004118D4
Direct3D9: (ERROR) : [6] : Address 00411702
Direct3D9: (ERROR) : [7] : Address 00412C58
Direct3D9: (ERROR) : [8] : Address 004129BF
Direct3D9: (ERROR) : [9] : Address 7C816D4F
Direct3D9: (ERROR) : [10] : Address 00000000
Direct3D9: (ERROR) : [11] : Address 00000000
Direct3D9: (ERROR) : [12] : Address 00000000
Direct3D9: (ERROR) : [13] : Address 00000000
Direct3D9: (ERROR) : [14] : Address 00000000
Direct3D9: (ERROR) : [15] : Address 00000000
Direct3D9: (WARN) :Memory Address: 00842848 lAllocID=9 dwSize=00000120, (pid=0000071c)
Direct3D9: (WARN) : Stack Back Trace
Direct3D9: (ERROR) : [0] : Address 00C9572F
Direct3D9: (ERROR) : [1] : Address 00C91D65
Direct3D9: (ERROR) : [2] : Address 4FDFAF2E
Direct3D9: (ERROR) : [3] : Address 004118D4
Direct3D9: (ERROR) : [4] : Address 00411702
Direct3D9: (ERROR) : [5] : Address 00412C58
Direct3D9: (ERROR) : [6] : Address 004129BF
Direct3D9: (ERROR) : [7] : Address 7C816D4F
Direct3D9: (ERROR) : [8] : Address 00000000
Direct3D9: (ERROR) : [9] : Address 00000000
Direct3D9: (ERROR) : [10] : Address 00000000
Direct3D9: (ERROR) : [11] : Address 00000000
Direct3D9: (ERROR) : [12] : Address 00000000
Direct3D9: (ERROR) : [13] : Address 00000000
Direct3D9: (ERROR) : [14] : Address 00000000
Direct3D9: (ERROR) : [15] : Address 00000000
Direct3D9: (WARN) :Total Memory Unfreed From Current Process = 19576 bytes
Direct3D9: :====> EXIT: DLLMAIN(00c9d6e0): Process Detach 0000071c
The program '[1820] d3d_windowed.exe: Native' has exited with code 0 (0x0).

I hope that isn't a bit too much...

Quote:
Original post by Evil Steve
It still sounds to me like missing drivers, or are running in safe mode / via remote desktop. Have you tried getting the latest drivers for your graphics card?


uhh..No, I'm looking for one now. The computer that I am working on is a dinosaur. My newer one is currently down, unfortunately.

Share this post


Link to post
Share on other sites
Quote:
Original post by computergeek101234
Quote:
Original post by Evil Steve
It still sounds to me like missing drivers, or are running in safe mode / via remote desktop. Have you tried getting the latest drivers for your graphics card?


uhh..No, I'm looking for one now. The computer that I am working on is a dinosaur. My newer one is currently down, unfortunately.
Ah, that's most likely the problem - it looks like your graphics card can't handle DX9, or can only do 2D. The only time I've ever seen this warning:
Direct3D9: (WARN) :driver set D3DDEVCAPS_TEXTURENONLOCALVIDMEM w/o DDCAPS2_NONLOCALVIDMEM:turning off D3DDEVCAPS_TEXTURENONLOCALVIDMEM
was from my extremely old "Diamond Monster TNT2" graphics card, which was around in ~1998.

What graphics card do you have?

Share this post


Link to post
Share on other sites
Quote:
Original post by computergeek101234
Okay, I think this is the graphics card.

Intel(R) 82810 Graphics Controller
There's a driver download link on Intel's site Here. Although the features list looks pretty bad, and I don't think you'll realistically get anywhere with DX9 and this graphics card (And Intel chipsets are nutoriously bad anyway).

Share this post


Link to post
Share on other sites
Hmm, looking over the debug output again, there's not actually anything there saying that CreateDevice() failed. Is it actually failing (I.e. is the device pointer NULL after the CreateDevice() call)?

Also, are you running a 24-bit display mode (Control panel -> Display will tell you)? If so, you could try D3DFMT_R8G8B8 as a backbuffer format and see if that works.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Hmm, looking over the debug output again, there's not actually anything there saying that CreateDevice() failed. Is it actually failing (I.e. is the device pointer NULL after the CreateDevice() call)?


Returning null.

Quote:
Original post by Evil Steve Also, are you running a 24-bit display mode (Control panel -> Display will tell you)? If so, you could try D3DFMT_R8G8B8 as a backbuffer format and see if that works.


Yes, I'm running a 24-bit, unfortunately.

Okay, tried setting the backbuffer format to D3DFMT_R8G8B8, now i'm getting the "Direct3D9: (ERROR) :Invalid value for BackBufferFormat. ValidatePresentParameters fails." error again.

Share this post


Link to post
Share on other sites
Quote:
Original post by computergeek101234
Yes, I'm running a 24-bit, unfortunately.

Okay, tried setting the backbuffer format to D3DFMT_R8G8B8, now i'm getting the "Direct3D9: (ERROR) :Invalid value for BackBufferFormat. ValidatePresentParameters fails." error again.
Last thing I can think of is using GetAdapterDisplayMode to see if it returns a format other than D3DFMT_R8G8B8, and using that format.

Failing that, I doubt there's anything you can really do.

Share this post


Link to post
Share on other sites
okay. Thanks for all of your help, I'll try that and see if it works. If it doesn't, I'll just wait until my other computer is fixed. I really appreciate your help, I know that I'm a pain in the butt sometimes, so thanks for dealing with me, lol.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement