CreateDevice failing

This is a discussion on CreateDevice failing within the Game Programming forums, part of the General Programming Boards category; I can't figure out why this code is failing, it's basic so its frustrating. The message "arg" always displays meaning ...

  1. #1
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735

    CreateDevice failing

    I can't figure out why this code is failing, it's basic so its frustrating. The message "arg" always displays meaning that CreateDevice is failing for whatever reason.

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, 
                          GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                          "Real Earth Engine test App", NULL };
        RegisterClassEx( &wc );
        HWND hWnd = CreateWindow( "Engine", "Public Demo", 
                                  WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
                                  GetDesktopWindow(), NULL, wc.hInstance, NULL );
    	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
    	{
    		return false;
    	}
    	D3DPRESENT_PARAMETERS d3dpp; 
    	ZeroMemory( &d3dpp, sizeof(d3dpp) );
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
        if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                          &d3dpp, &g_pd3dDevice ) ) )
    	{
    		MessageBox(NULL, "arg", NULL, NULL);
    		return -1;
    	}
    }
    thank you

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    your back buffer's dimensions are 0x0

  3. #3
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    I don't understand what you mean?

    What do I need to do to fix the problem

    Thanks

  4. #4
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    Code:
    d3dpp.BackBufferWidth = 800;
    d3dpp.BackBufferHeight = 600;
    You need those. There might be some other required settings too, I'll post a default version for you with everything set so you can get an idea of the other members:
    Code:
    D3DPP.BackBufferWidth = 800;
    D3DPP.BackBufferHeight = 600;
    D3DPP.BackBufferFormat = D3DFMT_A8R8G8B8;
    D3DPP.BackBufferCount = 1;
    D3DPP.MultiSampleType = D3DMULTISAMPLE_NONE;
    D3DPP.MultiSampleQuality = 0;
    D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
    D3DPP.hDeviceWindow = hwnd;
    D3DPP.Windowed = true;
    D3DPP.EnableAutoDepthStencil = true;
    D3DPP.AutoDepthStencilFormat = D3DFMT_D24S8;
    D3DPP.Flags = 0;
    D3DPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
    Sic vis pacum para bellum. If you want peace, prepare for war.

  5. #5
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Arg, the dang thing still pops up

    Code:
    #include <d3d9.h>
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	LPDIRECT3D9 g_pD3D = NULL;
    	LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
    	HWND hWnd = NULL;
    	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
    	{
    		return -1;
    	}
    	D3DPRESENT_PARAMETERS d3dpp; 
    	ZeroMemory( &d3dpp, sizeof(d3dpp) );
    	d3dpp.BackBufferCount = 1;
    	d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
    	d3dpp.BackBufferHeight = 1024;
    	d3dpp.BackBufferWidth = 768;
    	d3dpp.EnableAutoDepthStencil = false;
    	d3dpp.Flags = 0;
    	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    	d3dpp.hDeviceWindow = hWnd;
    	d3dpp.MultiSampleQuality = 0;
    	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.Windowed = FALSE;
        if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                          &d3dpp, &g_pd3dDevice ) ) )
    	{
    		MessageBox(NULL, "Fail", NULL, NULL);
    		return -1;
    	}
    	return 0;
    }
    Now I'm off for homework, sleep, and then to check out a Direct3D book

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    well, as a rule of thumb, whenever I work on cars..

    Say the pressure gague is giving you a 0 rating...

    What is the first thing you check?

    The pressure gague!

    So check your if statement
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You don't have to set the dimensions, leaving them out will use the dimensions of the window you use (since you have Windowed == TRUE).

    You should sheck the return-value form CreateDevice to see exactly what error you get. It may be something simple like your system not supporting A8R8G8B8 back buffers (note the A, I've had trouble with this before, try X8R8G8B8 instead).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-23-2008, 03:32 AM
  2. pointer comparison failing
    By Bleech in forum C Programming
    Replies: 4
    Last Post: 08-11-2007, 06:33 PM
  3. CreateDevice returning D3DERR_NOTAVAILABLE
    By cboard_member in forum Game Programming
    Replies: 5
    Last Post: 05-28-2006, 10:09 AM
  4. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 09:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21