Jump to content
  • Advertisement
Sign in to follow this  
Tubos

CreateDevice D3DERR_INVALIDCALL - How to solve without debug runtime?

This topic is 2480 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

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! smile.png

Share this post


Link to post
Share on other sites
Advertisement
* 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.[/quote]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.[/quote]
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".

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.[/quote]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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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? :)

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!