Sign in to follow this  
MuchoPichu

MDX device failure (again!)

Recommended Posts

Hi Folks, I know I have seen something similar on here before, but unfortunately I did not understand the solution. So! Hoping some kind folks will lend me a hand. I am experimenting with MDX and finding that I cannot compile the C# tutorials included in the DX9 SDK, nor any of my home grown concoctions. Basically the failure is always at this line:
device = new Device(0, DeviceType.Software, this, CreateFlags.SoftwareVertexProcessing, presentParams);


I have tried all four possible variations of DeviceType and don't get anything that will work. The debug run time tells me: A first chance exception of type 'System.NullReferenceException' occurred in Microsoft.DirectX.Direct3D.dll An unhandled exception of type 'System.NullReferenceException' occurred in Microsoft.DirectX.Direct3D.dll Additional information: Object reference not set to an instance of an object. I'm sure that means that I am not setting something up right, but the question would be what? I am running these on a crappy little laptop with no GPU and I'm sure whatever would be the crappiest graphics card ever made. Some settings that I have tried are:

         // Set our presentation parameters
            PresentParameters presentParams = new PresentParameters();

            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;
            presentParams.AutoDepthStencilFormat = DepthFormat.D16;
            presentParams.EnableAutoDepthStencil = true;


And these correspond to what I usually run in un-managed DX w/o problems. Eh, any suggestions appreciated! Thanks - Mucho. [/source]

Share this post


Link to post
Share on other sites
Assuming your hardware supports a D16 z-buffer format (which it probably does - you can check with the DX caps viewer) the only thing that stands out to me is DeviceType.Software in the Device constructor because thats used when you're supplying DX with a plugin software rasterizer. You probably want to change that to DeviceType.Hardware even though you're doing the vertex processing in software (even the worst graphics hardware out there provides fixed function capability for pixel rasterization, however limited it may be which is why we have the caps bits). Or you can try DeviceType.Reference - if it still fails then the problem is elsewhere.

Hope that helps

Daz

[edit] duh, didn't see that you'd tried the other types - sorry! The only thing I do differently is to specify the backbuffer size and count.

presentParams.PresentationInterval = PresentInterval.Immediate;
presentParams.BackBufferWidth = this.ClientSize.Width;
presentParams.BackBufferHeight = this.ClientSize.Height;
presentParams.BackBufferCount = 1;
presentParams.BackBufferFormat = Format.Unknown;

If I change one of my projects to use your code exactly but with DeviceType.Hardware it works fine. Have you tried putting a try/catch around the call then seeing what the exception contains? For example if I change the code to DeviceType.Software I get an DirectXException with D3DERR_INVALIDCALL which is what I'd expect.

[Edited by - djr on March 1, 2008 8:51:27 AM]

Share this post


Link to post
Share on other sites
Hi Djr -

Thanks alot for your reply, I appreciate it. I tried inserting your code, but unfortunately that didn't solve the problem. Still the same thing - crashing on new device();

Incidentally, the exception being thrown by that statement is:

"System.NullReferenceException"

And that occurs whether the device type is to Hardware and Software. Sheesh!

I will take a look at Caps, but I am wondering if there exists a comprehensive checklist of all the things one needs to check before calling "device()".

Also wondering, since this is the first time that I have run MDX, is there some way to confirm that it has been installed with all compatible versions of .NET, etc.. I am at a loss becuase I can't even get the SDK tutorials to compile at the moment.

Thanks - Mucho.

Share this post


Link to post
Share on other sites
Although I don't want to discourage you away from MDX, you should know that MDX has been officially canned by Microsoft, and they will no longer be providing updates, even for bug fixes. Also, the samples and documentation have been removed from the latest SDK.

What this means is that at the very least you are going to find it hard to use, lacking in documentation and in communities of people who are using. Plus, MDX targets .NET 1.1, which means it is old and ugly compared to newer code for .NET 2.0.

Since using C# is much more preferable than using C++, we create SlimDX, which is a managed wrapper around DirectX, and is similar in concept to MDX.

If you want to take a look at a minimalistic application in SlimDX that draws a triangle to the screen, check out this from our wiki.

Share this post


Link to post
Share on other sites
What version of the SDK are you using? What versions of the dll's are you referencing? The Oct 2007 SDK was IIRC the last release containing the full MDX (samples, docs etc), the latest release contains the dll's but nothing else.

You should be referencing v1.0.2902.0 for Microsoft.DirectX and Microsoft.DirectX.Direct3D, the latest Microsoft.DirectX.Direct3DX is v1.0.2911.0.

You could try this (cobbled together, don't blame me if its wrong) code and just see what it comes back with:



try
{
Format fmt = Manager.Adapters[0].CurrentDisplayMode.Format;
if (!Manager.CheckDepthStencilMatch(0, DeviceType.Hardware, fmt, fmt, DepthFormat.D16))
MessageBox.Show("DepthFormat.D16 unsupported");

presentParams = new PresentParameters();
presentParams.Windowed = true;

// Keep as discard, its the only valid SwapEffect if we use multisampling
presentParams.SwapEffect = SwapEffect.Discard;

// Do not wait for vsync, set to One or Default if vsync is required
presentParams.PresentationInterval = PresentInterval.Immediate;
presentParams.BackBufferWidth = this.ClientSize.Width;
presentParams.BackBufferHeight = this.ClientSize.Height;
presentParams.BackBufferCount = 1;
presentParams.BackBufferFormat = Format.Unknown;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;

device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);

}
catch (Exception ex)
{
if (ex is DirectXException)
MessageBox.Show((DirectXException) ex).ErrorString);
}



The DirectXException will return the DX error code which you can then lookup in the unmanaged docs for the related method (in this case IDirect3D9::CreateDevice) - sometimes that helps trace the source of the error.

Pretty much the same code minus the depthstencil match works for me on integrated Intel 845 graphics hardware which is probably just as limited as your platform.

But as Mike says MDX is now unsupported so you might be better off looking at SlimDX or XNA where there is a lot more help available these days. I'll be jumping ship eventually when I can decide where to jump to...

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