Sign in to follow this  

INVALIDCALL with CreateDevice

Recommended Posts

Would the D3D debug runtime component help me fix this problem? I enabled it, but I'm not sure how to use it. Anyway, in CPP: init_finish.h:
struct D3DInitialization_Destruction {
	//last 13 parameters are for D3DPRESENT_PARAMETERS
	void d3d_init (	IDirect3D9* pDObj,
			IDirect3DDevice9* pDObjDev,
			HWND hwnd,
			UINT buffW,
			UINT buffH,
			bool wind,
			D3DFORMAT buffF = D3DFMT_R8G8B8,
			UINT buffC = 1,
			bool autoDnS = FALSE,
			UINT flags = 0,

		p.BackBufferWidth = buffW;
		p.BackBufferHeight = buffH;
		p.BackBufferFormat = buffF;
		p.BackBufferCount = buffC;
		p.MultiSampleType = MST;
		p.SwapEffect = swapEffect;
		p.hDeviceWindow = hwnd;
		p.Windowed = wind;
		p.EnableAutoDepthStencil = autoDnS;
		p.AutoDepthStencilFormat = autoDnSFormat;
		p.Flags = flags;
		p.FullScreen_RefreshRateInHz = FS_RefRate;
		p.PresentationInterval = FS_PresInt;

		pDObj = Direct3DCreate9 (D3D_SDK_VERSION);
		int msg;
		msg = pDObj->CreateDevice (0, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &p, &pDObjDev);
		if (msg == D3D_OK)
			MessageBox (hwnd, "device created!", NULL, 0);
		else if (msg == D3DERR_NOTAVAILABLE)
			MessageBox (hwnd, "NOTAVAILABLE", NULL, 0);
		else if (msg == D3DERR_INVALIDCALL)
			MessageBox (hwnd, "INVALIDCALL", NULL, 0);
		else if (msg == D3DERR_OUTOFVIDEOMEMORY)
			MessageBox (hwnd, "OUTOFVIDEOMEMORY", NULL, 0);
			MessageBox (hwnd, "unknown error", NULL, 0);
#include <assert.h>
#include <afxwin.h>
#include "d3d9.h"
#include "init_finish.h"

//inside WinMain:
IDirect3D9* DObj = NULL;
IDirect3DDevice9* DObjDev = NULL;
hafta.d3d_init (DObj, DObjDev, hwnd, 640, 480, TRUE);
I get the INVALIDCALL messagebox, but my window doesn't crash as I've seen happens to others'. I think one of the last two parameters in pDObj->CreateDevice is the problem due to the fact that hwnd works with the message boxes, and the other parameters are pretty straightforward. By the way, does any Windows message box (I also mean stuff like assert) halt a program until it goes away again?

Share this post

Link to post
Share on other sites
From a quick look at your code, I'd put money on it being the D3DFMT_R8G8B8 backbuffer format default. 24bit formats have been fairly rare for quite a while now - it's much more common to find X888 or 8888 rather than 888. Try changing that default value to D3DFMT_X8R8G8B8.

There's no guarantee that such things are supported by your hardware and you'll get an invalid-call error in that case. Look into using IDirect3D9::CheckDeviceType() to validate your height/width/format BEFORE calling CreateDevice() (or do a full enumeration using IDirect3D9::EnumAdapterModes()). For windowed mode you can save some time and grab the current properties using IDirect3D9::GetAdapterDisplayMode().


Share this post

Link to post
Share on other sites
D3DFMT_R8G8B8 isn't a valid backbuffer format in Direct3D 9 on any hardware.
Straight from the direct3d help:

These formats are the only valid formats for a back buffer or a display.

Format Back buffer Display
A2R10G10B10 x x (full-screen mode only)
A8R8G8B8 x
X8R8G8B8 x x
A1R5G5B5 x
X1R5G5B5 x x
R5G6B5 x x

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this