当可见区域更改时,OpenGL 插件会使 Chrome 崩溃
我正在 Windows 上使用 FireBreath 开发一个插件(目前),其中包括使用 OpenGL 显示网络摄像头源。我正在使用窗口插件,并且从单独的线程中绘图。代码可以在这里查看:
头文件
源文件
(忽略onWindowResized中的奇怪代码,这只是一些测试保留在提交中。)
问题是,一旦浏览器窗口的大小被重新调整,从而导致插件的可见区域发生变化,或者扩展程序以某种方式滚动到滚动框的可见区域之外,插件在 Chrome 中崩溃。我还没有安装 Firefox,但我猜它是 NpApi 的东西,因为它可以在 Internet Explorer 中运行。
我相信每当插件的可见尺寸发生变化时,Chrome 就会发布并创建一个新的 HDC。这可能会导致渲染上下文无效,但它仍在插件中使用,从而导致崩溃。
我注意到发生这种情况时会调用 NPP_SetWindow get ,但这些调用在 NpapiPluginModule_NPP.cpp 中被忽略,因此我无法挂钩此事件。
我已经谷歌了几个小时了,但没有找到任何帮助。有人有这方面的经验吗?
我有一个想法,如果我在插件窗口中创建自己的子窗口,在那里我可以处理自己的 DC,它就可以工作。我做了一些失败的快速测试,这可能是因为我蹩脚的 Win32 技能。但这还需要做更多的工作吗?我的另一个想法是以某种方式跟踪可见区域,但我还没有研究过这个。
I'm developing a plugin using FireBreath on Windows (for now) that among other things is displaying a webcam feed using OpenGL. I'm using a windowed plugin and I'm drawing from a separate thread. The code can be viewed here:
Header file
Source file
(Ignore the strange code in onWindowResized, it's just some testing that remained in the commit.)
The problem is that as soon as the browser window is re-sized so that the visible region of the plugin is changed or the the extension is somehow scrolled outside the visible area of the scroll box, the plugin crashes in Chrome. I haven't got Firefox installed but I'm guessing it's a NpApi thing, since it's working in Internet Explorer.
I believe what is happening is that Chrome releases and creates a new HDC whenever the visible dimensions of the plugin is changed. This probably results in that the Rendering Context is invalid, but it is still being used in the plugin and that causes the crash.
I've noticed NPP_SetWindow get's called when this happens, but those calls are ignored in NpapiPluginModule_NPP.cpp, so my there is no way of hooking in to this event.
I've Google for several hours now but without finding any help. Does anyone have any experience of this?
I have an idea that it could work if I created my own child window to the plugin window where I could handle my own DC. I did some quick testing that failed, which is probably because of my lame Win32 skills. But could this work with some more work? Another idea I have is to track the visible region somehow, but I haven't looked in to this yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Windows 句柄无效不应导致程序崩溃。但是 OpenGL,即它的扩展需要一些特殊的预防措施,特别是如果主机程序也使用 OpenGL。
任何使用 OpenGL 的插件或 DLL 都必须小心,即在使用所需资源之前将其置于正常状态,并在使用后将其放回原处。对于 OpenGL,这意味着,每次开始使用它之前,您都应该重新绑定上下文:
由于在 Window 扩展函数中指针依赖于上下文,因此将它们放入一个结构中并通过该结构调用它们是有意义的。这节省了整个扩展重新初始化的事情。在 C++ 中,您可以将整个 OpenGL 上下文包装在一个类中。
请记住,每次通过 NP-API 调用您的插件时,您都需要执行此设置/拆卸。
Windows handles getting invalid should not cause a program to crash per so. But OpenGL, namely its extensions require some special precautions, especially if the host program makes use of OpenGL as well.
Any kind of plugin or DLL that makes use of OpenGL must take care, that is puts its required resources into a sane state before using them, and put them back once done. For OpenGL this means, everytime before you start using it you should rebind your context:
Since in Window extension functions pointers depend on the context it makes sense to put them into a structure and call them through that one. This saves the whole extension reinitialisation thing. In C++ you could wrap the whole OpenGL context in a class for this.
Remember that you need to go through this setup/teardown everytime your plugin gets called through NP-API.