E_INVALIDARG:向返回函数传递了一个无效参数
本文关键字:一个 参数 无效 INVALIDARG 返回 函数 | 更新日期: 2023-09-27 17:57:33
我试图制作一个简单的SlimDX示例来测试与GDI的一些性能,但不幸的是,我一开始就陷入了困境。我在VS2010中创建了一个简单的控制台应用程序,并将此代码添加到程序中。主要方法:
// 0. STEP
SlimDX.Direct3D10.Device device = new SlimDX.Direct3D10.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport);
SlimDX.Direct2D.Factory factory = new SlimDX.Direct2D.Factory();
// 1. STEP
Texture2DDescription textureDesc = new Texture2DDescription();
textureDesc.Width = 512;
textureDesc.Height = 512;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
textureDesc.SampleDescription = new SampleDescription(1, 0);
textureDesc.Usage = ResourceUsage.Default;
textureDesc.BindFlags = BindFlags.RenderTarget;
textureDesc.CpuAccessFlags = CpuAccessFlags.None;
textureDesc.OptionFlags = ResourceOptionFlags.None;
Texture2D maskTexture = new Texture2D(device, textureDesc);
// 2. STEP
SlimDX.DXGI.Surface surface = maskTexture.AsSurface();
// 3. STEPpro
RenderTargetProperties props = new RenderTargetProperties
{
HorizontalDpi = 96,
VerticalDpi = 96,
MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
PixelFormat = new PixelFormat(SlimDX.DXGI.Format.Unknown, AlphaMode.Premultiplied),
Type = RenderTargetType.Default,
Usage = RenderTargetUsage.None
};
RenderTarget target = RenderTarget.FromDXGI(factory, surface, props);
这在RenderTarget上崩溃。从DXGI调用并显示以下消息:
Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)
不幸的是,我无法启用DirectX调试输出,如这个SO问题所述:DirectX 10调试输出不工作
所以,这就是我的全部。
但是,我在家里(win8.1,vs2013)和工作中(win7,vs2010sp1)都尝试过,在家里,当我从2013年开始使用图形诊断调试应用程序时,它就可以工作了。当我开始常规调试或尝试手动启动exe时,它不起作用。在工作中,它根本不起作用。
仅仅从代码中有什么想法吗?我有点绝望(
我刚刚注意到你对我另一个答案的评论。这是我使用的创建功能:
public static Texture2D CreateRenderTexture(this RenderHelper helper, int width, int height)
{
Texture2DDescription description = new Texture2DDescription
{
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
Width = width,
Height = height,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
Usage = ResourceUsage.Default,
};
return new Texture2D(helper.Device, description);
}