后台线程中的ISurfaceImageSourceNativeWithD2D ComException E_FAIL [英] ISurfaceImageSourceNativeWithD2D ComException E_FAIL in background thread

查看:64
本文介绍了后台线程中的ISurfaceImageSourceNativeWithD2D ComException E_FAIL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C#项目中我使用VirtualSurfaceImageSource和ComWrappers来渲染一些数据。 VSIS已投放到 ISurfaceImageSourceNativeWithD2D 。 ID3D11Device是使用  D3D11_CREATE_DEVICE_BGRA_SUPPORT初始化的
,默认情况下支持多线程。但是SISN.beginDraw方法导致带有HResult的ComException:E_FAIL,如果在后台线程中调用它。我尝试使用ID3D11Device(IDXGISurface
作为输出结果)以及ID2D1Device(ID2D1DeviceContext作为输出结果),结果是相同的。

in my project on C# I use VirtualSurfaceImageSource and ComWrappers to render some data. VSIS is casted to ISurfaceImageSourceNativeWithD2D. ID3D11Device is initialized with D3D11_CREATE_DEVICE_BGRA_SUPPORT and supports multithreding by default. But SISN.beginDraw method cause a ComException with HResult: E_FAIL, if it is called  in background thread. I've try to use this with ID3D11Device (IDXGISurface as output result) and also with ID2D1Device(ID2D1DeviceContext as output result), result was the same.

它已经过测试赢得8.1和VS2013专业版。此处链接示例  项目

It was tested on Win 8.1 and VS2013 pro. Here link on sample Project

重现的步骤:

1)打开项目并启动应用程序

1) Open project and launch app

那么,是否可以在不使用C ++的情况下从后台线程开始工作?

So, is it possible to make it work from background thread without using C++?

推荐答案

Hi Mikhail Maksyuta,

Hi Mikhail Maksyuta,

欢迎来到这里!

我已转载您的问题并找到原因,请查看您编写的代码:

I have reproduced your issue and found the reason, please look at the code you written:

 while(true) {
                if (TaskList.Count != 0)
                {
                    BackgroundRenderTaskInfo taskInfo = TaskList[0];
                    TaskList.RemoveAt(0);

                    ISurfaceImageSourceNativeWithD2D threadsSurface = taskInfo.SurfaceImageSource;

                    IDXGISurface surface = null;
                    RECT originalRect = taskInfo.SourceRect;
                    POINT offset = new POINT();
                    Guid guid = new Guid(DirectX.IIDS.IDXGISurface);
                    await uiDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        POINT offset1;
                        threadsSurface.BeginDraw(ref originalRect, ref guid, out surface, out offset1);

                        //threadsSurface.BeginDraw(originalRect, out surface, ref offset);
                        offset = offset1;
                    });

                    await uiDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        //threadsSurface.SuspendDraw();
                        threadsSurface.EndDraw();
                    });

                    Marshal.ReleaseComObject(surface);
                }
                            }

当我设置断点时,我发现它会在TaskList.Count == 0时进入无限循环,并且出错是显示。

When I set a breakpoint, I find it will go into a infinite loop while TaskList.Count==0, and the error is display.

只需添加"else return;"将解决问题。

Just add "else return;" will fix the issue.

像这样:

if (TaskList.Count != 0) { BackgroundRenderTaskInfo taskInfo = TaskList[0]; TaskList.RemoveAt(0); ISurfaceImageSourceNativeWithD2D threadsSurface = taskInfo.SurfaceImageSource; IDXGISurface surface = null; RECT originalRect = taskInfo.SourceRect; POINT offset = new POINT(); Guid guid = new Guid(DirectX.IIDS.IDXGISurface); await uiDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { POINT offset1; threadsSurface.BeginDraw(ref originalRect, ref guid, out surface, out offset1); //threadsSurface.BeginDraw(originalRect, out surface, ref offset); offset = offset1; }); await uiDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { //threadsSurface.SuspendDraw(); threadsSurface.EndDraw(); }); Marshal.ReleaseComObject(surface); } else return; }

希望它有用! :)

问候!


这篇关于后台线程中的ISurfaceImageSourceNativeWithD2D ComException E_FAIL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆