E_INVALIDARG: An invalid parameter was passed to the returning function

我的未来我决定 提交于 2019-12-02 17:57:59

问题


I'm trying to make simple SlimDX example to test some performance vs GDI and unfortunately I got stuck on the very beginning. I've created simple Console Application in VS2010 and added this code to programs main method:

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

This crashes on the RenderTarget.FromDXGI call with this message:

Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

Unfortunately, I could not enable DirectX debug output as stated in this SO question: DirectX 10 debug output not working

... so, this is all I've got.

BUT, I've tried this both at home (win8.1, vs2013) and at work (win7, vs2010sp1) and at home it works when I debug the app using Graphics Diagnostics from 2013. It doesn't work when I start regular debug or try to start exe manualy. At work it does not work at all.

Any ideas just from code? I'm kinda desperate here. :(


回答1:


I just noticed your comment on my other answer. Here is the creation function I use:

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


来源:https://stackoverflow.com/questions/22934324/e-invalidarg-an-invalid-parameter-was-passed-to-the-returning-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!