- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 D3DImage 作为我的 WPF 用户控件的一部分。极少数情况下,在渲染时,D3DImage.TryLock 会失败。
到目前为止,我还没有找到任何关于 D3D.TryLock 为什么会失败的文档。有谁知道为什么会发生这种情况?
最佳答案
Look at this在备注部分。它指出:
Occasionally, the front buffer becomes unavailable. This lack of availability can be caused by screen locking, full-screen exclusive Direct3D applications, user-switching, or other system activities. When this occurs, your WPF application is notified by handling the IsFrontBufferAvailableChanged event.
它说的是与 Unlock
方法的关系,该方法将后缓冲区内容推送到前缓冲区。但我想,如果你获得一个锁并调用 Unlock
,此时它失败了,因为它无法写入 frontbuffer 无论出于何种原因,锁可能会保留直到成功解锁,此时调用 TryLock
会失败。我想象这样的事情:
image.TryLock
// image gets written to
image.Unlock // fails for one of the listed reasons, lock is retained
// loop
image.TryLock // fails because lock is already acquired
image.Unlock // succeeds because the previously successful lock is still in
// place and the issue that caused the previous failure of Unlock
// has since subsided.
我已经看到在使用 BeginDraw
和 EndDraw
不当时,在某些原生 DirectX 开发中会出现此问题,所以这可能是您的解决方案。这就是我的全部。希望对您有所帮助!
如该 block 注释中所述,您可以通过向 IsFrontBufferAvailableChanged
事件添加一个事件来检查是否属于这种情况。如果不是,您可以通过不调用 TryLock
/Unlock
组合来适本地处理该问题,实质上是在前台缓冲区不可用时跳过渲染。有关此事件处理程序的更多信息,请参见 here .以及关于this page的评论了解有关在引发此事件时如何更好地处理的更多信息。它指出:
The SetBackBuffer method has an overload that takes a parameter that specifies whether WPF falls back to software rendering.
关于c# - D3DImage TryLock 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21834735/
我是一名优秀的程序员,十分优秀!