Jump to content

  • Log In with Google      Sign In   
  • Create Account


CreateDevice D3DERR_INVALIDCALL - How to solve without debug runtime?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Tubos   Members   -  Reputation: 152

Like
0Likes
Like

Posted 15 January 2012 - 04:06 PM

Hi!

For some users of my game, CreateDevice fails with D3DERR_INVALIDCALL.

I initialize the device like this:
Windowed
DepthStencil: True, D16
Multisampling: None Quality 0
Present Flags: None
Backbuffer format: Unknown

If that doesn't work, my software tries the same parameters with software vertex processing.
If that doesn't work, it tries to initialize the device without depth buffer.

For a significant number of users, all three attempts fail.

What could cause this problem?
I cannot use the debug runtime as I have no machine where I can reproduce the problem.

I appreciate any ideas! Posted Image

Sponsor:

#2 programci_84   Members   -  Reputation: 335

Like
1Likes
Like

Posted 16 January 2012 - 02:33 AM

* Check for device support. For example, if you want a HAL device, and D3DFMT_D16 for depthbuffer and D3DFMT_R5G6B5 for backbuffer and the device don't support them, device creation will fail.

* Check D3DPRESENT_PARAMETERS object you filled. Don't forget to zeroe the object first, then begin filling. Like this:
D3DPRESENT_PARAMETERS pp;
::RtlZeroMemory (&pp, sizeof (pp));

bool _windowed = true; //I suppose
pp.AutoDepthStencilFormat		= D3DFMT_D24X8;
pp.EnableAutoDepthStencil		= true;
pp.BackBufferCount				= 1;
pp.BackBufferFormat				= D3DFMT_X8R8G8B8;
pp.BackBufferHeight				= 0;
pp.BackBufferWidth				= 0;
pp.Flags						= D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
pp.FullScreen_RefreshRateInHz	= 0;
pp.hDeviceWindow				= 0;
pp.MultiSampleQuality			= 0;
pp.MultiSampleType				= D3DMULTISAMPLE_NONE;;
pp.PresentationInterval			= D3DPRESENT_INTERVAL_IMMEDIATE;
pp.SwapEffect					= D3DSWAPEFFECT_DISCARD;
pp.Windowed						= _windowed;

If you don't zeroe pp object and don't fill some members, those members will get random values (e.g. pp.MultisampleQuality = 135438734 or pp.BackBufferCount = 87684543). So, IDirect3D9::CreateDevice() will fail.

hth.
-R
There's no "hard", and "the impossible" takes just a little time.

#3 Evil Steve   Members   -  Reputation: 1955

Like
0Likes
Like

Posted 16 January 2012 - 03:49 AM

Can we see your device setup code? A windowed device with the backbuffer format set to D3DFMT_UNKNOWN and no Z-buffer should almost never fail.

Steve Macpherson
Senior programmer, Firebrand Games


#4 Tubos   Members   -  Reputation: 152

Like
0Likes
Like

Posted 17 January 2012 - 03:27 AM

If you don't zeroe pp object and don't fill some members, those members will get random values (e.g. pp.MultisampleQuality = 135438734 or pp.BackBufferCount = 87684543). So, IDirect3D9::CreateDevice() will fail.

Sorry, I forgot to mention that this is SlimDX. I think this situation is impossible .NET, data members are always initialized.

Check for device support. For example, if you want a HAL device, and D3DFMT_D16 for depthbuffer and D3DFMT_R5G6B5 for backbuffer and the device don't support them, device creation will fail.

The backbuffer format is D3DFMT_UNKNOWN since I'm in windowed mode. This should always work.
The depthbuffer format cannot be the reason, since the call fails even without any depthbuffer.

Here is my code:


PresentParameters parameters = new PresentParameters();
parameters.Windowed = true;
parameters.SwapEffect = SwapEffect.Discard;
parameters.BackBufferCount = 1;

if (windowed)
{
parameters.BackBufferWidth = backbufferSize.Width;
parameters.BackBufferHeight = backbufferSize.Height;
}
else
{
Rectangle screenSize = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
parameters.BackBufferWidth = screenSize.Width;
parameters.BackBufferHeight = screenSize.Height;
}

var currentDisplayFormat = Direct3D.GetAdapterDisplayMode(adapterToUse).Format;
Result result;
bool checkdeviceFormat = Direct3D.CheckDeviceFormat(adapterToUse, deviceType, currentDisplayFormat, Usage.DepthStencil, ResourceType.Surface, depthStencilFormat, out result);

// check whether 24bit is supported
// note: info from gamedev.net: you should both use CheckDeviceFormat AND CheckDepthStencilMatch
if (checkdeviceFormat && Direct3D.CheckDepthStencilMatch(adapterToUse, deviceType, currentDisplayFormat, currentDisplayFormat, depthStencilFormat))
parameters.AutoDepthStencilFormat = depthStencilFormat;
else
parameters.AutoDepthStencilFormat = Format.D16; // fallback

parameters.EnableAutoDepthStencil = true;

if (vSync)
parameters.PresentationInterval = PresentInterval.Default;
else
parameters.PresentationInterval = PresentInterval.Immediate;

parameters.BackBufferFormat = Format.Unknown; // for windowed mode, this takes the current display format.
if (multiSampling)
parameters.Multisample = MyDevice.GetMaximumMultisampleLevel(0, deviceType, parameters);


bool failure = false;
MyDevice device = null;

try
{
device = Create(adapterToUse, deviceType, control, CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve, parameters);
}
catch (Direct3D9Exception exc)
{ failure = true; }

if (failure)
{
failure = false;
try
{
// Hardware vertex processing not available. Trying software...
device = MyDevice.Create(adapterToUse, DeviceType.Hardware, control, CreateFlags.SoftwareVertexProcessing| CreateFlags.FpuPreserve, parameters);
}
catch (Direct3D9Exception)
{ failure = true; }

if (failure || Result.Last.IsFailure)
{
// Both hardware and vertex processing failed.
// Try it without depth buffer.
bool itWorksWithoutDepthBuffer = true;
try{
var paramWithoutDepth = parameters.Clone();
paramWithoutDepth.EnableAutoDepthStencil=false;
device=MyDevice.Create(adapterToUse, DeviceType.Hardware, control, CreateFlags.HardwareVertexProcessing, paramWithoutDepth);}
catch(Direct3D9Exception) { withoutDepthBuffer=false;}

throw new SlimException("Cannot initialize Graphics Card. Without depth buffer = "+itWorksWithoutDepthBuffer);
}
}
Note the exception in the last line. This exception gets sent to me via the internet automatically, no matter whether the last init worked or not. So far, all error reports say "Without depth buffer = false".

#5 Evil Steve   Members   -  Reputation: 1955

Like
0Likes
Like

Posted 17 January 2012 - 04:16 AM

What are the values of vsync, multiSampling, adapterToUse, and deviceType? Using a v-sync type of anything other than "Default" and a multisampling type of anything other than "None" will fail in Windowed mode. Your adapterToUse should be whateverthe SlimDX equivalent of D3DADPATER_DEFAULT is, and deviceType should be the SlimDX equivalent of D3DDEVTYPE_HAL.

Steve Macpherson
Senior programmer, Firebrand Games


#6 Tubos   Members   -  Reputation: 152

Like
0Likes
Like

Posted 17 January 2012 - 04:45 AM

The vast majority of users have this parameters:
vsync = true, PresentInterval = PresentInterval.Default
Multisampling = None, Quality 0
Present Flags = None
adapterToUse = 0. I checked the source code, this value is passed directly to DirectX. And D3DADAPTER_DEFAULT=0 in DirectX.


Overall, the problem affects about 2-4% of all users. This is quite significant and I don't think it's some random driver error.

Using a v-sync type of anything other than "Default" [..] will fail in Windowed mode.

You mean that vsync other than Default _can_ fail or _will_ fail? Because PresentInterval.Immediate works just fine on my machine in windowed mode. However, most users with the problem will have vsync=true because it's the default setting.

#7 Evil Steve   Members   -  Reputation: 1955

Like
1Likes
Like

Posted 18 January 2012 - 03:58 AM

Err - you're right, for some reason I thought it was only valid to use "default" in windowed mode. So ignore what I said about the presentation interval :)

Is there any way you can get a build to run on one of the machines that fails using a fixed set of parameters to MyDevice.Create()? So get rid of all variables and so on, and just hard code the PresentParameters and device creation flags? Just to rule out as much as possible.

Steve Macpherson
Senior programmer, Firebrand Games


#8 Adam_42   Crossbones+   -  Reputation: 2364

Like
1Likes
Like

Posted 18 January 2012 - 06:24 AM

It might be worth making your crash reporter send you more info about their system, for example what video card do they have? What operating system?

Maybe they don't have a card that supports DX9, or don't have drivers for it?

I also noticed that the "try it without depth buffer" code uses CreateFlags.HardwareVertexProcessing. I'd go with software processing for maximum compatibility.

#9 Tubos   Members   -  Reputation: 152

Like
0Likes
Like

Posted 19 January 2012 - 05:36 AM

Thanks for your excellent suggestions!

I implemented all of them to get better error reports. I'll post what I found out after receiving a few more of them.

#10 Tubos   Members   -  Reputation: 152

Like
0Likes
Like

Posted 26 February 2012 - 02:35 PM

I have some results!

The users with the above problem have the following graphics cards, as reported by DirectX:
"Standard VGA Adapter": 20 users
Graphics Adapter just shows up as empty string: 7 users
Intel onboard: 6 users
Some modern graphics card (ATI or NVidia): 3 users <-- let's ignore those few.

I think "Standard VGA ADapter" could mean that no graphics card driver is installed. It might also mean that no graphics card is installed and it's just onboard.
I will probably write those users and ask them to look at their computer case and see whether there's an ATI or NVidia sticker and then install their respective graphics card driver (NVidia or ATi).

What are your thoughts on the "Standard VGA Adapter" issue? :)

#11 Adam_42   Crossbones+   -  Reputation: 2364

Like
0Likes
Like

Posted 26 February 2012 - 06:22 PM

Generally even onboard graphics cards need some sort of driver. It's certainly possible that the graphics card they do have doesn't have the correct driver installed. The other possibility is that there is no D3D9 supporting driver available because the graphics card is ancient, or they are using a virtual machine that doesn't do 3D acceleration.

The Intel ones may simply have an out of date driver, or be such old hardware that they don't support D3D9. Same goes for the ATI and NVidia ones.

Possible code based solutions:
- Tell the user something like "Direct3D initialization failed. Make sure you have a DirectX 9 compatible graphics card and an up to date driver installed. Or contact technical support".
- If any of them are running Vista or 7 then supporting D3D11 would allow you to fix it automatically by falling back on the software renderer (WARP). This will obviously be much slower than hardware rendering though. Of course adding D3D11 support isn't a small task either.

#12 Tubos   Members   -  Reputation: 152

Like
0Likes
Like

Posted 02 March 2012 - 09:01 AM

Sounds like a good idea. I will give them instructions how to get the correct graphics card driver, or to contact me.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS