【问题标题】:E_INVALIDARG One or more arguments are invalid. - CreateDeviceE_INVALIDARG 一个或多个参数无效。 - 创建设备
【发布时间】:2014-02-04 18:41:47
【问题描述】:

我有一个 d3dDevice:

ComPtr<ID3D11Device1>d3dDevice;

我在这里将它用于 dxgiDevice:

    ComPtr<IDXGIDevice3> dxgiDevice2;

    HRESULT hr;

    hr = d3dDevice.As( &dxgiDevice2 ); // S_OK

    hr = d2dFactory->CreateDevice( dxgiDevice2.Get(), d2dDevice.GetAddressOf() ); // E_INVALIDARG One or more arguments are invalid

    hr = d2dDevice->CreateDeviceContext(
        D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
        &d2dDeviceContext
        );

为什么这个错误会在运行时发生?

http://msdn.microsoft.com/en-us/library/windows/desktop/dn280482(v=vs.85).aspx

与问题相关的全部代码:http://pastebin.com/P7Rs9xdh

【问题讨论】:

  • 你试过&amp;d2dDevice吗?
  • @ichramm 为什么? GetAddressOf 语法没有任何问题——这实际上是 MS 现在显示其示例代码的方式。

标签: c++ windows-8 directx


【解决方案1】:

问题是您尚未创建与 Direct2D 兼容的 DX11 设备。您需要传递正确的创建标志,还应该考虑定义所需的功能级别。比如:

// This flag adds support for surfaces with a different color channel 
// ordering than the API default.
// You need it for compatibility with Direct2D.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;

// This array defines the set of DirectX hardware feature levels this 
// app supports.
// The ordering is important and you should  preserve it.
// Don't forget to declare your app's minimum required feature level in its
// description.  All apps are assumed to support 9.1 unless otherwise stated.
D3D_FEATURE_LEVEL featureLevels[] =
{
    D3D_FEATURE_LEVEL_11_1,
    D3D_FEATURE_LEVEL_11_0,
    D3D_FEATURE_LEVEL_10_1,
    D3D_FEATURE_LEVEL_10_0,
    D3D_FEATURE_LEVEL_9_3,
    D3D_FEATURE_LEVEL_9_2,
    D3D_FEATURE_LEVEL_9_1
};

D3D_FEATURE_LEVEL m_featureLevel;

// Create 3D device and device context objects
D3D11CreateDevice(
    nullptr,
    D3D_DRIVER_TYPE_HARDWARE,
    nullptr,
    creationFlags,
    featureLevels,
    ARRAYSIZE(featureLevels),
    D3D11_SDK_VERSION,
    &d3dDevice11,
    &m_featureLevel,
    &d3dDeviceContext11); 

【讨论】:

  • ARGHHHHHHHHHH,Ofcourseeeeee...让我回家后试试。如果这是正确的,我会吻你,你这个 schmexy 男人!
  • 别害羞了……哈哈。不过我很期待这样做……不是亲吻,我的意思是看看它是否有效。会及时通知您!
猜你喜欢
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多