E_INVALIDARG: An invalid parameter was passed to the returning function
Asked Answered
A

1

0

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. :(

Amphithecium answered 8/4, 2014 at 10:30 Comment(4)
You need to pass DeviceCreationFlags.Debug to the Device constructor in order to get debug output. I am not sure if a render target may be created with an unknown pixel format. Does not make much sense to me. Especially if the underlying texture has a known format. Btw, it is much more comfortable to use the Device.CreateWithSwapChain method to create a device and render target.Antimonyl
1) When I try to create device with Debug flag, I get this error: E_FAIL: An undetermined error occurred; 2) I've set render target's format to be the same as texture as you suggested; 3) I do not need to render to visual control so I'm not using swapchain. I just need to render some lines to texture and then export it to bitmap.Amphithecium
Have you installed the DirectX SDK which is included in the Windows SDK for some time?Antimonyl
On my home machine (win8.1) I've installed Windows SDK, and on my work machine (win7) I've installed DirectX SDK. I've also set DebugLevel.Information to D2D factory so that I can get more log info, but I keep getting "Unable to load D2D debug layer" even though I installed it additionaly from this link: msdn.microsoft.com/en-us/library/dd940309%28VS.85%29.aspxAmphithecium
B
0

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);
    }
Bellamy answered 20/4, 2014 at 21:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.