Sign in to follow this  
Grenadiac

[.net] MDX throws exception on "new Device"

Recommended Posts

I'm currently working with a team on a Managed Direct3D app in c#, and we are having strange issues that seem to be related to SP2. We have been able to reproduce this issue on multiple machines of various configurations, but have been unable to find any insight at all into what the root cause of the problem may be. The app initializes fine, but once it tries to create the Direct3D device, it throws a NullReferenceException. We are creating the device using this line (which is the standard method of creation that I've seen in many examples)
device = new Device(0, DeviceType.Software, pbRender, CreateFlags.SoftwareVertexProcessing, presentParams);

However - here's where it get's interesting. It seems to ONLY throw the error on machines that are PRE-WindowsXP SP2. Installing SP2 fixes the problem most of the time. This error occurs in the samples that are included with the DirectX SDK October 2004 update as well. This makes no sense to me - installing the latest DirectX 9.0c runtime available on Microsoft's website does not help - only pc's running SP2 are able to run the app or any of the sample apps in the SDK. I've asked some users on our site to run the 3d text MDX sample on their machines to get a sampling of who could have installation problems if we continue on the MDX path. It turns out only about 13% had no problem (not very encouraging to say the least). Here is the link to my poll: http://www.halomods.com/forums/viewtopic.php?t=18379 If anyone has experienced this issue (i'm sure it has to be common despite the lack of information) we'd appreciate any insight into the cause and any workarounds or suggestions that you might have. I have been unable to find any information on this issue, and because of this, I have no idea on how to proceed. I'm sure that we can expect our end users to experience the same issues that we are having, and we definately can't 'require' a SP2 upgrade - that makes no sense.

Share this post


Link to post
Share on other sites
That sounds quite odd. I haven't heard of it myself -- what about posting about Microsoft's DirectX newsgroups? The people there will probably have additional experience with these issues.

Share this post


Link to post
Share on other sites
Is one of your parameters particularly unusual or esoteric or something? I tried a number of different initialization combinations and all the devices initialized just fine. You may need to post some more code.

Share this post


Link to post
Share on other sites

public bool Initialize3d() {
try {
// Setup our D3D stuff
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, pbRender,
CreateFlags.HardwareVertexProcessing, presentParams);

// Turn on the z-buffer.
device.RenderState.ZBufferEnable = true;

// Turn off culling, so the user sees the front and back of the triangle
device.RenderState.CullMode = Cull.None;

// Turn off Direct3D lighting, since object provides its own vertex colors
device.RenderState.Lighting = false;

return true;
}



The sample app i sent around to our users was from the October SDK, called csText3d.exe.

Share this post


Link to post
Share on other sites
Do you have a stack trace? Looks like the people on the other forum were having a IOException and not a NullReference, do you think that it is the same error? pbRender is a window of some sort right? Has it been shown?

Share this post


Link to post
Share on other sites
What is the debug runtime output? Also note that your PresentParameter setup requires the render window to be focused. A call of pbRender.Focus() before the device creation *might* help.

Share this post


Link to post
Share on other sites
I thought I should post back with our eventual solution to the problem since it may help somebody else.

1) The users need DirectX 9.0c installed as well as .NET 1.1

2) It seemed that not everybody had the latest MDX installed (even with 9.0c?), so we distributed a new test app with the october 2004 MDX dlls as part of the assembly.

3) Before creating the device, check the hardware caps and make sure the hardware vertex processing is supported before passing that parameter into Device(). Otherwise use CreateFlags.SoftwareVertexProcessing.

4) One of our devs seemed to think that it had something to do with the SampleFramework class in the MDX samples. Creating our own setup from the ground up seemed to work better for some reason. I cannot confirm this suspicion, but there could possibly be something to it.

I think our initial suspicion of SP2 was due in part to the tendency for higher performance video card users to keep their drivers and service packs more up to date. A red herring I guess...

Grenadiac

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