space928 / WebView2_TextureStreamSample

GNU General Public License v3.0
1 stars 0 forks source link

CreateTextureStream return -2147024809 Value does not fall within the expected range. #1

Open jzp-oos opened 2 weeks ago

jzp-oos commented 2 weeks ago

// 开始创建工厂创建 D3D 的逻辑 var dxgiFactory2 = DXGI.DXGI.CreateDXGIFactory1();

            var hardwareAdapter = GetHardwareAdapter(dxgiFactory2)
                // 这里 ToList 只是想列出所有的 IDXGIAdapter1 在实际代码里,大部分都是获取第一个
                .ToList().FirstOrDefault();
            if (hardwareAdapter == null)
            {
                throw new InvalidOperationException("Cannot detect D3D11 adapter");
            }

            // 功能等级
            // [C# 从零开始写 SharpDx 应用 聊聊功能等级](https://blog.lindexi.com/post/C-%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E5%86%99-SharpDx-%E5%BA%94%E7%94%A8-%E8%81%8A%E8%81%8A%E5%8A%9F%E8%83%BD%E7%AD%89%E7%BA%A7.html)
            D3D.FeatureLevel[] featureLevels = new[]
            {
        D3D.FeatureLevel.Level_11_1,
        D3D.FeatureLevel.Level_11_0,
        D3D.FeatureLevel.Level_10_1,
        D3D.FeatureLevel.Level_10_0,
        D3D.FeatureLevel.Level_9_3,
        D3D.FeatureLevel.Level_9_2,
        D3D.FeatureLevel.Level_9_1,
    };

            DXGI.IDXGIAdapter1 adapter = hardwareAdapter;
            D3D11.DeviceCreationFlags creationFlags = D3D11.DeviceCreationFlags.BgraSupport;
            var result = D3D11.D3D11.D3D11CreateDevice
            (
                adapter,
                D3D.DriverType.Unknown,
                creationFlags,
                featureLevels,
                out  d3D11Device, out D3D.FeatureLevel featureLevel,
                out d3D11DeviceContext
            );

            if (result.Failure)
            {
                // 如果失败了,那就不指定显卡,走 WARP 的方式
                // http://go.microsoft.com/fwlink/?LinkId=286690
                result = D3D11.D3D11.D3D11CreateDevice(
                    IntPtr.Zero,
                    D3D.DriverType.Warp,
                    creationFlags,
                    featureLevels,
                    out d3D11Device, out featureLevel, out d3D11DeviceContext);

                // 如果失败,就不能继续
                result.CheckError();
            }
            return;
space928 commented 2 weeks ago

This repo was only ever intended as a quick test case for a bug report. The reason that my code fails to create the texture stream is because the feature didn't get enabled properly.

I needed to add this when creating the WebView2Environment to get it to work.

    std::wstring args;
    args.append(L"--enable-features=msWebView2TextureStream");
    auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
    options->put_AdditionalBrowserArguments(args.c_str());

   [...]

   CreateCoreWebView2EnvironmentWithOptions(nullptr, userDataFolderPath.c_str(), options.Get(), [...]

Your issue might be related, but I have no idea, you didn't provide enough code...