My app crashed inside Qt internal function



  • I want to make a QtQuick app that show some 3D model. However when I run the program, the main window will show for a blink, then it crashes instantly. The debugger shows it is inside Qt inner rendering function, so I have no idea of how to find it out.

    The model is contained in a QSGGeometry:
    @
    // Profile3DWidget is my subclass of QQuickItem
    void Profile3DWidget::build_shape()
    {
    std::printf("begin Profile3DWidget::build_shape\n");
    QSGGeometry::Attribute attrs[] = {
    QSGGeometry::Attribute::create(0, 4, GL_FLOAT, true),
    QSGGeometry::Attribute::create(1, 4, GL_FLOAT, false),
    };

    QSGGeometry::AttributeSet attr_set = {2, sizeof(float)*8, attrs};
    
    std::printf("create geometry\n");
    shape = new QSGGeometry(attr_set, 4, 4, GL_UNSIGNED_INT);
    node->setGeometry(shape);
    shape->setDrawingMode(GL_TRIANGLE_STRIP);
    
    std::printf("set vertex data\n");
    MyVertex* vertices = (MyVertex*)shape->vertexData();
    vertices[0].set_position(-10, -10, 0, 1);
    vertices[0].set_color(1, 0, 0, 1);
    vertices[1].set_position(10, -10, 0, 1);
    vertices[1].set_color(0, 1, 0, 1);
    vertices[2].set_position(10, 10, 0, 1);
    vertices[2].set_color(0, 0, 1, 1);
    vertices[3].set_position(-10, 10, 0, 1);
    vertices[3].set_color(0.5, 0.5, 0.5, 1);
    
    std::printf("set index data\n");
    uint* indices = shape->indexDataAsUInt();
    indices[0] = 0;
    indices[1] = 1;
    indices[2] = 2;
    indices[3] = 3;
    
    std::printf("end Profile3DWidget::build_shape\n");
    

    }
    @

    This is the implemented updatePaintNode function. The node is already created in Profile3DWidget constructor. We simply update its matrix, and return it.
    @
    QSGNode* Profile3DWidget::updatePaintNode(QSGNode * old_node, UpdatePaintNodeData * data)
    {
    std::printf("begin Profile3DWidget::updatePaintNode\n");
    if (!shape)
    build_shape();

    QSGTransformNode* transform_node = data->transformNode;
    
    QMatrix4x4 mat = matrix_project;
    mat *= matrix_camera;
    mat *= matrix_object;
    transform_node->setMatrix(mat);
    
    std::printf("end Profile3DWidget::updatePaintNode: return %p\n", node);
    return node;
    

    }
    @
    And these are some key functions of the re-implemented shader class. The GLSL code is a simple vertex and color processor, so I don't post it here:
    @
    char const* const* DataProfileShader::attributeNames() const
    {
    static const char* const names[] = {"vtx", "vtx_color", 0};
    return names;
    }

    void DataProfileShader::updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
    {
    Q_ASSERT(program()->isLinked());

    if (state.isMatrixDirty())
    {
        program()->setUniformValue(id_matrix, state.combinedMatrix());
    }
    

    }
    void DataProfileShader::initialize()
    {
    QSGMaterialShader::initialize();
    id_matrix = program()->uniformLocation("matrix");
    }
    @
    This is the crash back trace:
    @
    0 ?? /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff79554d6
    1 QSGBatchRenderer::Renderer::renderBatches() /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff79566bd
    2 QSGBatchRenderer::Renderer::render() /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff795cfea
    3 QSGRenderer::renderScene(QSGBindable const&) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff796918e
    4 QSGRenderer::renderScene() /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff7969587
    5 QSGRenderContext::renderNextFrame(QSGRenderer*, unsigned int) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff7976e48
    6 QQuickWindowPrivate::renderSceneGraph(QSize const&) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff79b5d78
    7 ?? /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff7993326
    8 ?? /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff7993e9e
    9 QWindow::event(QEvent*) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Gui.so.5 0x7ffff6034909
    10 QQuickWindow::event(QEvent*) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Quick.so.5 0x7ffff79c00cb
    11 QApplicationPrivate::notify_helper(QObject*, QEvent*) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Widgets.so.5 0x7ffff6b15724
    12 QApplication::notify(QObject*, QEvent*) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Widgets.so.5 0x7ffff6b18d46
    13 QCoreApplication::notifyInternal(QObject*, QEvent*) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Core.so.5 0x7ffff5ae0fc4
    14 QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent*) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Gui.so.5 0x7ffff6028587
    15 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Gui.so.5 0x7ffff602f665
    16 QWindowSystemInterface::sendWindowSystemEvents(QFlagsQEventLoop::ProcessEventsFlag) /home/yangxi/software/Qt/5.3/gcc_64/lib/libQt5Gui.so.5 0x7ffff60145b8
    17 ?? /home/yangxi/software/Qt/5.3/gcc_64/plugins/platforms/libqxcb.so 0x7fffeeeeca70
    18 g_main_context_dispatch /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff4277c5d
    19 ?? /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff4277f48
    20 g_main_context_iteration /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff4277ffc
    ...
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.