Direct3D 9 创建和释放线程?
我有一个使用 Direct3D 渲染视口的应用程序,它是作为一个独立于主应用程序的 DLL 模块而在运行时链接到它的。主要应用程序是 C# 程序。
Direct3D设备及其资源的创建和初始化是在本机DLL端完成的。主 C# 程序仅从此 DLL 请求一个窗口。现在,由于主 GUI 循环位于 C# 可执行文件中,因此每当视口关闭/销毁时,它都必须调用 DLL 函数来请求释放相关的 Direct3D 设备/资源。
问题是,在尝试释放 Direct3D 设备时,程序会出现紧急情况。它表示有一个不同的线程(我猜是主 C# 程序,因为它将消息发送到 DLL),而不是创建设备并试图释放它。
有解决这个问题的方法吗?有什么想法吗?
我正在使用 Direct3D 9。
感谢帮助。
I have an application that uses Direct3D for rendering viewports and it's made as a separate DLL module from the main application which links to it at run-time. The main application is a C# program.
The creation and initialization of Direct3D device and its resources are done on the native DLL end. The main C# program only request a window from this DLL. Now since the main GUI loop is in the C# executable, whenever a viewport is closed/destroyed it has to call a DLL function to request release of related Direct3D device/resources.
The problem is that upon trying to release the Direct3D device, the program panics. It says that a different thread (the main C# program I guess since it's sending the message to the DLL) than that created the device trying to release it.
Is there a work around this problem? Any thoughts?
I'm using Direct3D 9.
Help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
D3D 设备调用都与创建它们的线程具有线程关联性。
您必须将回调编组回主 D3D 线程,或者使用 D3DCREATE_MULTITHREADED 初始化设备,以便允许从多个线程使用它。
D3D Device calls all have thread affinity with the thread on which they were created.
You have to either marshal the call back to the main D3D thread, or initialize the device with D3DCREATE_MULTITHREADED in order to allow it to be used from multiple threads.