簡體   English   中英

C#:無法創建DirectX設備。 硬件類型或軟件類型均無效

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

我正在嘗試通過以下代碼創建DirectX設備:

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);

問題在於,這僅適用於某些計算機(例如我的工作計算機),而不適用於其他計算機(具體來說是Panasonic CF-19 Toughbook)。 我已經檢查以確保有問題的PC通過dxdiag啟用了硬件加速,並且仍然不會出錯。

不幸的是,我收到的唯一錯誤消息是“應用程序錯誤”。 我什至在上面的代碼之間插入了幾個消息框,似乎從來沒有碰過ex1和ex2 catch塊。

有想法該怎么解決這個嗎?

編輯:對不起,我才意識到我忘了顯示我的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;

解決了。 該死,我已經很蠢了。

將PresentParameters減少到僅這三行,即可在Toughbook上使用。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM