   D3D error (d3ddev), access violoation?
  Ok I'm following a directx tutorial, and I get an error (I'll bold the line I get the error on, I'm sure it has to do with d3ddev though)The error I get is Unhandled exception at 0x00411848 in testte.exe: 0xC0000005: Access violation reading location 0x00000000.// include the basic windows header files and the Direct3D header file#include <windows.h>#include <windowsx.h>#include <d3d9.h>// include the Direct3D Library file#pragma comment (lib, "d3d9.lib")// global declarationsLPDIRECT3D9 d3d;    // the pointer to our Direct3D interfaceLPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class// function prototypesvoid initD3D(HWND hWnd);    // sets up and initializes Direct3Dvoid render_frame(void);    // renders a single framevoid cleanD3D(void);    // closes Direct3D and releases memory// the WindowProc function prototypeLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);// the entry point for any Windows programint WINAPI WinMain(HINSTANCE hInstance,    HINSTANCE hPrevInstance,    LPSTR lpCmdLine,    int nCmdShow){    HWND hWnd;    WNDCLASSEX wc;    ZeroMemory(&wc, sizeof(WNDCLASSEX));    wc.cbSize = sizeof(WNDCLASSEX);    wc.style = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc = (WNDPROC)WindowProc;    wc.hInstance = hInstance;    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    wc.lpszClassName = L"WindowClass1";    RegisterClassEx(&wc);    hWnd = CreateWindowEx(NULL, L"WindowClass1", L"Our First Direct3D Program", WS_OVERLAPPEDWINDOW, 300, 300, 640, 480, NULL, NULL, hInstance, NULL);    ShowWindow(hWnd, nCmdShow);    // set up and initialize Direct3D    initD3D(hWnd);    // enter the main loop:    MSG msg;    while(TRUE)    {   DWORD starting_point = GetTickCount();   if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))   {  if (msg.message == WM_QUIT) break;  TranslateMessage(&msg);  DispatchMessage(&msg);   }   render_frame();   while ((GetTickCount() - starting_point) < 25);    }    // clean up DirectX and COM    cleanD3D();    return msg.wParam;}// this is the main message handler for the programLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    switch(message)    {   case WM_DESTROY:  { PostQuitMessage(0); return 0;  } break;    }    return DefWindowProc (hWnd, message, wParam, lParam);}// this function initializes and prepares Direct3D for usevoid initD3D(HWND hWnd){    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D    // create a device class using this information and the info from the d3dpp stuct    d3d->CreateDevice(D3DADAPTER_DEFAULT,  D3DDEVTYPE_HAL,  hWnd,  D3DCREATE_SOFTWARE_VERTEXPROCESSING,  &d3dpp,  &d3ddev);    return;}// this is the function used to render a single framevoid render_frame(void){    // clear the window to a deep blue    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);    d3ddev->BeginScene();    // begins the 3D scene    // do 3D rendering on the back buffer here    d3ddev->EndScene();    // ends the 3D scene    d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen    return;}// this is the function that cleans up Direct3D and COMvoid cleanD3D(void){    d3ddev->Release();    // close and release the 3D device    d3d->Release();    // close and release Direct3D    return;}
  The error sounds clear. One of your objects (like you said, probably the D3D Device) was not created properly. Make sure to run with the debug runtimes to get a more explanitary error message.   ;  Hmm, I just pasted your code into an empty project in MSVC and it ran fine without any access violation.If creation of your Direct3D device failed for some reason, then your d3ddev pointer would be NULL (0x00000000) when the program then goes onto call the render_frame() function.A NULL d3ddev pointer would cause exactly the error you've posted. You can confirm that this is the case by clicking the Break or Debug (or similar) button on the error dialog, then hover the mouse pointer over the d3ddev-> part of the line that the debugger shows.D3D device creation could fail for a number of reasons, such as the drivers for your graphics card being very old or broken in some way; or possibly the window you're passing not being created properly for some reason.The best thing to do is use the debug Direct3D runtime to see why CreateDevice() failed. Enable it and change the reporting level in the DirectX SDK control panel applet, run your application again, then look in the output window of your debugger to see if there are any error messages. I think there are more details of D3D debugging in the FAQ, both for this forum and in the SDK.   ;  Ok, thanks I think I know the solution (and problem).  It should work on other computers, as it's from a tutorial, with a screenshot.Anyways I think it's my graphics card. (I was planning on getting a new computer (this ones 6 years old :)) soon, with a new graphics card, but decided I could use this for basic 3D for now... maybe I was wrong?How do I go into debug mode to check? Thanks.Edit: I changed it to debug from the control panel: I get the following error:Direct3D9: (ERROR) :No hardware acceleration is available in the current modeI think it's my drivers or graphics card now.  I'll try this same code at my other new computer when I go there.   ;Quote:Original post by solinentHow do I go into debug mode to check? Thanks.Here's one Ken (DrunkenHyena) prepared earlier [smile]:http://www.drunkenhyena.com/cgi-bin/view_cpp_article.pl?chapter=1;article=4The FAQ for this forum has some more too:http://www.gamedev.net/community/forums/showfaq.asp?forum_id=10#q61;  I changed it via the control panel.  I'll have a look there and see though.   ;Quote:Original post by solinentEdit: I changed it to debug from the control panel: I get the following error:Direct3D9: (ERROR) :No hardware acceleration is available in the current modeI think it's my drivers or graphics card now.  I'll try this same code at my other new computer when I go there.Yeah, it is your graphics card. Assuming the SDK is set up, try using the REF device (change D3DDEVTYPE_HAL to D3DDEVTYPE_REF in the device creation). This should run through software, but will be extremely slow.   ;  Thanks alot!  It worked.  I'll get a new graphics card and PC soon.Anyways can you give me a link to the disadvantages of HAL vs REF?   ;Quote:Original post by solinentThanks alot!  It worked.  I'll get a new graphics card and PC soon.Anyways can you give me a link to the disadvantages of HAL vs REF?I'll look for a link. Basically, HAL can use your graphics card to render. REF is a software attempt to represent a GPU. It supports everything that DirectX supports, even if you graphics card does not. However, since it is run on the CPU, it is guaranteed to be extremely slow. Also, you can only use the Ref device if you have the SDK installed.Edit: Here is the basic Microsoft page on the device type. It doesn't go into alot of detail. Really the HAL device should always be used. A REF device is only necessary if you  need to test features your card cannot handle (as in your case).   ;Quote:Original post by solinentDirect3D9: (ERROR) :No hardware acceleration is available in the current modeI think it's my drivers or graphics card now.  I'll try this same code at my other new computer when I go there.Other than ancient hardware/old drivers/broken drivers, based on what that error message is saying, since your program is trying to start in windowed mode, I'd also check/try the following:1) go to the Display Properties for your desktop/PC, and check the "color quality" setting. Newer versions of Direct3D will only work if this is 16bit or 32bit. 8bit and 24bit will not work, so if it's set to either of those, try 16 or 32 instead!2) also, try reducing the resolution of your display so that the desktop uses less video memory.   