<small id='DdejU'></small><noframes id='DdejU'>

    <legend id='DdejU'><style id='DdejU'><dir id='DdejU'><q id='DdejU'></q></dir></style></legend>
    <i id='DdejU'><tr id='DdejU'><dt id='DdejU'><q id='DdejU'><span id='DdejU'><b id='DdejU'><form id='DdejU'><ins id='DdejU'></ins><ul id='DdejU'></ul><sub id='DdejU'></sub></form><legend id='DdejU'></legend><bdo id='DdejU'><pre id='DdejU'><center id='DdejU'></center></pre></bdo></b><th id='DdejU'></th></span></q></dt></tr></i><div id='DdejU'><tfoot id='DdejU'></tfoot><dl id='DdejU'><fieldset id='DdejU'></fieldset></dl></div>
      <bdo id='DdejU'></bdo><ul id='DdejU'></ul>
  1. <tfoot id='DdejU'></tfoot>
    1. QQuickFrameBufferObject导致PySide2崩溃

      时间:2024-08-21
          <tbody id='OaLN5'></tbody>
          1. <i id='OaLN5'><tr id='OaLN5'><dt id='OaLN5'><q id='OaLN5'><span id='OaLN5'><b id='OaLN5'><form id='OaLN5'><ins id='OaLN5'></ins><ul id='OaLN5'></ul><sub id='OaLN5'></sub></form><legend id='OaLN5'></legend><bdo id='OaLN5'><pre id='OaLN5'><center id='OaLN5'></center></pre></bdo></b><th id='OaLN5'></th></span></q></dt></tr></i><div id='OaLN5'><tfoot id='OaLN5'></tfoot><dl id='OaLN5'><fieldset id='OaLN5'></fieldset></dl></div>

              <tfoot id='OaLN5'></tfoot>
            • <legend id='OaLN5'><style id='OaLN5'><dir id='OaLN5'><q id='OaLN5'></q></dir></style></legend>

              <small id='OaLN5'></small><noframes id='OaLN5'>

              • <bdo id='OaLN5'></bdo><ul id='OaLN5'></ul>
              • 本文介绍了QQuickFrameBufferObject导致PySide2崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试创建一个简单的QQuickFrameBufferObject,以便在Qt Quick中渲染一些自定义OpenGL纹理。所以我决定用PySide2来测试它。下面是一个简单的实现:

                from PySide2.QtQuick import QQuickFramebufferObject
                from PySide2.QtGui import QOpenGLFramebufferObjectFormat, QOpenGLFramebufferObject
                from PySide2.QtCore import QSize, Qt
                
                class FboRenderer(QQuickFramebufferObject.Renderer):
                    def __init__(self, parent=None):
                        super().__init__(parent)
                        print("Creating renderer")
                
                    def createFrameBufferObject(self, size):
                        format = QOpenGLFramebufferObjectFormat()
                        format.setAttachment(QOpenGLFramebufferObject.Depth)
                        return QOpenGLFramebufferObject(size, format)
                
                    def synchronize(self, item):
                        print("Synchronizing")
                
                    def render(self):
                        print("Rendering")
                
                class OpenGLCanvas(QQuickFramebufferObject):
                    def __init__(self, parent=None):
                        super().__init__(parent)
                
                    def createRenderer(self):
                        return FboRenderer()
                

                然后要在我使用的QML中使用它:

                    qmlRegisterType(OpenGLCanvas,"OpenGLCanvas", 1, 0, "OpenGLCanvas")
                
                import QtQuick 2.12
                import QtQuick.Window 2.12
                import OpenGLCanvas 1.0
                
                Window{
                    id: win
                    visible: true
                
                    OpenGLCanvas{
                        anchors.fill: parent
                    }
                }
                
                现在应用程序运行并显示"正在创建渲染器",但几秒钟后就崩溃了。

                推荐答案

                问题是FboRenderer()是将立即销毁的局部变量,因此它还会销毁C++对象,从而导致分段错误,因为访问了未保留的内存。

                另一方面,createFrameBufferObject中有一个拼写错误,因为它必须是createFramebufferObject,这也显示了一个与初始错误类似的错误,因此解决方案也是类似的。

                class FboRenderer(QQuickFramebufferObject.Renderer):
                    def __init__(self):
                        super().__init__()
                        print("Creating renderer")
                        self._fbos = []
                
                    def createFramebufferObject(self, size):
                        fmt = QOpenGLFramebufferObjectFormat()
                        fmt.setAttachment(QOpenGLFramebufferObject.Depth)
                        fbo = QOpenGLFramebufferObject(size, fmt)
                        self._fbos.append(fbo)
                        return fbo
                
                    def synchronize(self, item):
                        print("Synchronizing")
                
                    def render(self):
                        print("Rendering")
                
                
                class OpenGLCanvas(QQuickFramebufferObject):
                    def __init__(self, parent=None):
                        super().__init__(parent)
                        self._renderer = None
                
                    def createRenderer(self):
                        if self._renderer is None:
                            self.renderer = FboRenderer()
                        return self.renderer
                

                这篇关于QQuickFrameBufferObject导致PySide2崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Django get()返回了多个 下一篇:QtMediaPlayer在无框架和半透明背景PyQt5上不起作用

                相关文章

                <legend id='jCXrq'><style id='jCXrq'><dir id='jCXrq'><q id='jCXrq'></q></dir></style></legend>
                <tfoot id='jCXrq'></tfoot>
                • <bdo id='jCXrq'></bdo><ul id='jCXrq'></ul>
              • <small id='jCXrq'></small><noframes id='jCXrq'>

                  1. <i id='jCXrq'><tr id='jCXrq'><dt id='jCXrq'><q id='jCXrq'><span id='jCXrq'><b id='jCXrq'><form id='jCXrq'><ins id='jCXrq'></ins><ul id='jCXrq'></ul><sub id='jCXrq'></sub></form><legend id='jCXrq'></legend><bdo id='jCXrq'><pre id='jCXrq'><center id='jCXrq'></center></pre></bdo></b><th id='jCXrq'></th></span></q></dt></tr></i><div id='jCXrq'><tfoot id='jCXrq'></tfoot><dl id='jCXrq'><fieldset id='jCXrq'></fieldset></dl></div>