C#: Unable to create DirectX device. Neither Hardware type or Software type works

1.7k views Asked by At

I'm trying to create a DirectX device through the following code:

Caps deviceCapability;
int deviceAdapter = Manager.Adapters.Default.Adapter;

try
{
    deviceCapability = Manager.GetDeviceCaps(
        deviceAdapter, DeviceType.Hardware);
}
catch (Exception ex1)
{
    try
    {
        deviceCapability = Manager.GetDeviceCaps(
            deviceAdapter, DeviceType.Software);
    }
    catch (Exception ex2)
    {
        deviceCapability = Manager.GetDeviceCaps(
            deviceAdapter, DeviceType.Reference);
    }
}

CreateFlags deviceFlags = CreateFlags.SoftwareVertexProcessing;
if(deviceCapability.DeviceCaps.SupportsHardwareTransformAndLight == true)
{
    deviceFlags = CreateFlags.HardwareVertexProcessing;
}

mDevice = new Device(deviceAdapter, deviceCapability.DeviceType,
    mInvisiblePanel, deviceFlags, mPresentParams);

The problem is that this only works on some computers (such as my work computer), while it doesn't on others (to be specific, a Panasonic CF-19 Toughbook). I've checked to make sure the offending PC has hardware acceleration enabled via dxdiag, and it still doesn't budge.

Unfortunately, the only error message I get is, "Error on the Application." I've even stuck several message boxes between the above code, and it never seems to hit the ex1 and ex2 catch block.

Any ideas on how to fix this?

Edit: Sorry, I just realized I forgot to show my PresentParameters.

// Setup the device parameters
PresentParameters mPresentParams = new PresentParameters();
mPresentParams.Windowed = true;
mPresentParams.SwapEffect = SwapEffect.Discard;
mPresentParams.AutoDepthStencilFormat = DepthFormat.D16;
mPresentParams.EnableAutoDepthStencil = true;
///* TODO: Anti-aliasing is not working
mPresentParams.MultiSample = MultiSampleType.NonMaskable;
mPresentParams.MultiSampleQuality = 0;
1

There are 1 answers

0
Japtar On BEST ANSWER

Solved it. Darn, I feel stupid already.

Reducing the PresentParameters to just these 3 lines made it work on the Toughbook.

// Setup the device parameters
PresentParameters mPresentParams = new PresentParameters();
mPresentParams.Windowed = true;
mPresentParams.SwapEffect = SwapEffect.Discard;