Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Segfault on invoking Q_INVOKABLE function



  • I'm writing a univerity task for artificial neuro nets course using Qt 5.7 and Qt Quick Controls 2 under fresh Archinux with GCC toolchain. Almost everything is OK but problem occurs when I try to call C++ functions marked with Q_IVOKABLE. At that point application crashes with a signal SIGSEGV. Help please, the task is almost written but that annoying error blocks all work.

    SingleLayerPerceptron.h

    #ifndef SINGLELAYERPERCEPTRON_H
    #define SINGLELAYERPERCEPTRON_H
    
    #include <QObject>
    #include <QVariantList>
    #include <cmath>
    
    class SingleLayerPerceptron : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QVariantList signal READ signal WRITE setSignal NOTIFY signalChanged)
        Q_PROPERTY(double mse READ mse)
    public:
        explicit SingleLayerPerceptron(QObject *parent = 0);
    
        QVariantList signal() const
        {
            return p_signal;
        }
    
        double mse() const
        {
            return p_mse;
        }
    
        Q_INVOKABLE void thetaClicked() {
            double sum1=0,sum2=0;
            double error[2];
            double d_w0[2];
            double d_w[2][640*410];
    
            for(int i=0;i<640*410;i++) {
                sum1 = sum1 + w[0][i]*(p_signal[i].toInt());
                sum2 = sum2 + w[1][i]*(p_signal[i].toInt());
            }
    
            sum1 += w[0][640*410];
            sum2 += w[1][640*410];
    
            result[0]=f(sum1);
            result[1]=f(sum2);
    
            // Переназначение весов по дельта правилу. Вектор (1,0) соответствует тэта, вектор (0,1) соответствует пси.
            error[0] = 1-result[0];
            error[1] = 0-result[1];
    
            //Считаем дельты w0
            for(int i=0;i<2;i++) {
                d_w0[i]=0.1*error[i]; //Скорость обучения делаем равной 0.1
            }
    
            //Считаем дельты w_ij
            for(int i=0;i<2;i++)
                for(int j=0;j<640*410;j++) {
                    d_w[i][j]=0.1*error[i]*(p_signal[j].toInt()); //Скорость обучения - 0.1
                }
    
            // Адаптируем веса
            for(int i=0;i<2;i++) {
                w[i][640*410] += d_w0[i];
            }
    
            for(int i=0;i<2;i++)
                for(int j=0;j<640*410;j++) {
                    w[i][j] += d_w[i][j];
                }
    
            p_mse = (error[0]*error[0] + error[1]*error[1])/2;
    
        }
    
        Q_INVOKABLE void psiClicked() {
            double sum1=0,sum2=0;
            double error[2];
            double d_w0[2];
            double d_w[2][640*410];
    
            for(int i=0;i<640*410;i++) {
                sum1 = sum1 + w[0][i]*(p_signal[i].toInt());
                sum2 = sum2 + w[1][i]*(p_signal[i].toInt());
            }
    
            sum1 += w[0][640*410];
            sum2 += w[1][640*410];
    
            result[0]=f(sum1);
            result[1]=f(sum2);
    
            // Переназначение весов по дельта правилу. Вектор (1,0) соответствует тэта, вектор (0,1) соответствует пси.
            error[0] = 0-result[0];
            error[1] = 1-result[1];
    
            //Считаем дельты w0
            for(int i=0;i<2;i++) {
                d_w0[i]=0.1*error[i]; //Скорость обучения делаем равной 0.1
            }
    
            //Считаем дельты w_ij
            for(int i=0;i<2;i++)
                for(int j=0;j<640*410;j++) {
                    d_w[i][j] = 0.1*error[i]*(p_signal[j].toInt()); //Скорость обучения - 0.1
                }
    
            // Адаптируем веса
            for(int i=0;i<2;i++) {
                w[i][640*410] += d_w0[i];
            }
    
            for(int i=0;i<2;i++)
                for(int j=0;j<640*410;j++) {
                    w[i][j] += d_w[i][j];
                }
    
            p_mse = (error[0]*error[0] + error[1]*error[1])/2;
    
        }
    
    signals:
        void signalChanged(QVariantList);
    
    public slots:
        void setSignal(QVariantList arg)
        {
            if(!(p_signal == arg)) {
                p_signal = arg;
                emit signalChanged(arg);
            }
        }
    
    private:
        double p_mse=NAN; //Среднеквадратичная ошибка
        double w[2][640*410+1]; //Матрица весов
        double result[2]; //Выходной сигнал
        QVariantList p_signal; //Сигналы
        int f(double); //Функция активации МакКаллока-Питца
    };
    
    #endif // SINGLELAYERPERCEPTRON_H
    
    

    SingleLayerPerceptron.cpp

    #include "singlelayerperceptron.h"
    #include <random>
    
    SingleLayerPerceptron::SingleLayerPerceptron(QObject *parent) : QObject(parent)
    {
        std::random_device rd;
        std::mt19937 gen(rd());
        std::uniform_real_distribution<double> dis(-0.1,0.1);
    
        for(int i=0;i<2;i++)
            for(int j=0;j<640*410+1;j++)
                w[i][j] = dis(gen);
    
    }
    
    int SingleLayerPerceptron::f(double x)
    {
        if (x>=0)
            return 1;
        else
            return 0;
    }
    
    

    main.cpp

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    #include "singlelayerperceptron.h"
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        SingleLayerPerceptron neuro;
        engine.rootContext()->setContextProperty("neuro", &neuro);
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        return app.exec();
    }
    

    main.qml

    import QtQuick 2.7
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.0
    
    Window {
        visible: true
        width: 640
        height: 480
        maximumHeight: height
        maximumWidth: width
        minimumHeight: height
        minimumWidth: width
        color: "white"
        title: "Обучение нейросети"
    
        Component.onCompleted: {
            setX(Screen.width/2 - width/2)
            setY(Screen.height/2 - height/2)
        }
    
    
        property int xpos
        property int ypos
        property int iterations:0
        property bool hold
        property bool clearCanvas:false
    
    
        Menu {
            id:popup
    
            MenuItem {
                text:"Итераций:" + iterations
                down: true
            }
    
            MenuItem {
                text:"Ошибка: " + neuro.mse
                down: true
            }
    
            MenuItem {
                text: "Сохранить нейросеть"
            }
        }
    
    
        Canvas {
            id:canvas
            anchors.top: parent.top
            width: 640
            height: 410
    
    
            onPaint: {
                var ctx = getContext('2d')
    
                if(clearCanvas) {
                    ctx.fillStyle = "white"
                    ctx.fillRect(0,0,width,height)
                    clearCanvas=false
    
                }
                else {
                    ctx.lineWidth = 5
                    ctx.strokeStyle = 'blue'
                    ctx.beginPath()
                    ctx.moveTo(xpos,ypos)
                    xpos = area.mouseX
                    ypos = area.mouseY
                    ctx.lineTo(xpos, ypos)
                    ctx.stroke()
                }
            }
    
            MouseArea {
                id:area
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton | Qt.RightButton
    
                onPressed: {
                    if(mouse.buttons & Qt.LeftButton) {
                        hold=true
                        xpos = mouseX
                        ypos = mouseY
                    }
                }
    
                onPositionChanged: {
                    if(hold & (mouse.buttons & Qt.LeftButton)) {
                        canvas.requestPaint()
                    }
    
                }
    
                onReleased: {
                    hold = false
                }
    
                onClicked: {
                    if(mouse.button === Qt.RightButton) {
                        popup.x = mouseX
                        popup.y = mouseY
                        popup.open()
                    }
                }
    
            }
        }
    
    
    
            Button {
                id:theta
    
                Text{
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.verticalCenter: parent.verticalCenter
    
                    text:"\u03F4"
                    font.pointSize: 18
                    color: "red"
                }
    
                height: 50
                width: 300
    
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.bottomMargin: 8
                anchors.leftMargin: 8
    
                onClicked: {
                    var image = canvas.getContext('2d').getImageData(0,0,canvas.width,canvas.height)
                    var norm_px = []
    
                    for(var i = 0, n=image.data.length; i<n; i+=4) {
                        if(image.data[i]===0 && image.data[i+1]===0 && image.data[i+2]===255 && image.data[i+3]===255) {
                            norm_px.push(1)
                        }
                        else
                        {
                            norm_px.push(0)
                        }
                    }
    
                    neuro.signal = norm_px
    
                    neuro.thetaClicked()
    
                    iterations++
                    canvas.requestPaint()
                    clearCanvas=true
                }
            }
    
            Button {
                id:psi
    
                Text {
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.verticalCenter: parent.verticalCenter
    
                    text:"\u03A8"
                    font.pointSize: 18
                    color: "red"
                }
    
                height: 50
                width: 300
    
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                anchors.bottomMargin: 8
                anchors.rightMargin: 8
    
                onClicked: {
                    var image = canvas.getContext('2d').getImageData(0,0,canvas.width,canvas.height)
                    var norm_px = []
    
                    for(var i = 0, n=image.data.length; i<n; i+=4) {
                        if(image.data[i]===0 && image.data[i+1]===0 && image.data[i+2]===255 && image.data[i+3]===255) {
                            norm_px.push(1)
                        }
                        else
                        {
                            norm_px.push(0)
                        }
                    }
    
                    neuro.signal = norm_px
    
                    neuro.psiClicked()
    
                    iterations++
                    canvas.requestPaint()
                    clearCanvas=true
                }
    
            }
    }
    
    

    ANN.pro

    TEMPLATE = app
    
    QT += qml quick
    CONFIG += c++11
    
    SOURCES += main.cpp \
        singlelayerperceptron.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    HEADERS += \
        singlelayerperceptron.h
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should run your application through a debugger to see what's going wrong.



  • @SGaist I have already done that. Placing breakpoints on "neuro.thetaClicked" and "neuro.psiClicked" in main.qml has not helped at all. Stepping into a function showed that application crash appears right after going into Q_INVOKABLE functions' bodies in singlelayerperceptron.h.
    At I first I thought it was incorrect bindning of QML and C++ in main.cpp in general but I can successfully read/write Q_PROPERTY attributes. An attempt to make needed methods public slots failed too for the same reason (application suddenly crashes silently without adequate message in console log at bottom of qt creator, debugger shows 'app received SIGSEGV from OS' right after entering to function body).


  • Qt Champions 2017

    When you get the segmentation fault extract the stack trace from Creator and paste it here, please.



  • @kshegunov

    Thread 7 (Thread 0x7fffd98c0700 (LWP 1045)):
    #0  0x00007ffff4fdd48d in poll () from /usr/lib/libc.so.6
    No symbol table info available.
    #1  0x00007ffff21e0066 in ?? () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #2  0x00007ffff21e017c in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #3  0x00007ffff628f047 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #4  0x00007ffff623fdca in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #5  0x00007ffff6076f1c in QThread::exec() () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #6  0x00007fffedcac115 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5DBus.so.5
    No symbol table info available.
    #7  0x00007ffff607b5f9 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #8  0x00007ffff5b46454 in start_thread () from /usr/lib/libpthread.so.0
    No symbol table info available.
    #9  0x00007ffff4fe67df in clone () from /usr/lib/libc.so.6
    No symbol table info available.
    
    Thread 6 (Thread 0x7fffdbfff700 (LWP 1044)):
    #0  0x00007ffff5b4c10f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
    No symbol table info available.
    #1  0x00007fffdaf4d4d3 in ?? () from /usr/lib/xorg/modules/dri/r600_dri.so
    No symbol table info available.
    #2  0x00007fffdaf4cc17 in ?? () from /usr/lib/xorg/modules/dri/r600_dri.so
    No symbol table info available.
    #3  0x00007ffff5b46454 in start_thread () from /usr/lib/libpthread.so.0
    No symbol table info available.
    #4  0x00007ffff4fe67df in clone () from /usr/lib/libc.so.6
    No symbol table info available.
    
    Thread 4 (Thread 0x7fffe9547700 (LWP 1041)):
    #0  0x00007ffff4fdd48d in poll () from /usr/lib/libc.so.6
    No symbol table info available.
    #1  0x00007ffff21e0066 in ?? () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #2  0x00007ffff21e017c in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #3  0x00007ffff628f05c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #4  0x00007ffff623fdca in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #5  0x00007ffff6076f1c in QThread::exec() () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #6  0x00007fffe999f837 in ?? () from /home/tikani/Qt/5.7/gcc_64/plugins/qmltooling/libqmldbg_server.so
    No symbol table info available.
    #7  0x00007ffff607b5f9 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #8  0x00007ffff5b46454 in start_thread () from /usr/lib/libpthread.so.0
    No symbol table info available.
    #9  0x00007ffff4fe67df in clone () from /usr/lib/libc.so.6
    No symbol table info available.
    
    Thread 3 (Thread 0x7fffeaba9700 (LWP 1040)):
    #0  0x00007ffff4fdd48d in poll () from /usr/lib/libc.so.6
    No symbol table info available.
    #1  0x00007ffff21e0066 in ?? () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #2  0x00007ffff21e017c in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #3  0x00007ffff628f047 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #4  0x00007ffff623fdca in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #5  0x00007ffff6076f1c in QThread::exec() () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #6  0x00007ffff6d10f35 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #7  0x00007ffff607b5f9 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #8  0x00007ffff5b46454 in start_thread () from /usr/lib/libpthread.so.0
    No symbol table info available.
    #9  0x00007ffff4fe67df in clone () from /usr/lib/libc.so.6
    No symbol table info available.
    
    Thread 2 (Thread 0x7fffeba08700 (LWP 1039)):
    #0  0x00007ffff4fdd48d in poll () from /usr/lib/libc.so.6
    No symbol table info available.
    #1  0x00007ffff07b48e0 in ?? () from /usr/lib/libxcb.so.1
    No symbol table info available.
    #2  0x00007ffff07b6679 in xcb_wait_for_event () from /usr/lib/libxcb.so.1
    No symbol table info available.
    #3  0x00007fffef11d3c9 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5XcbQpa.so.5
    No symbol table info available.
    #4  0x00007ffff607b5f9 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #5  0x00007ffff5b46454 in start_thread () from /usr/lib/libpthread.so.0
    No symbol table info available.
    #6  0x00007ffff4fe67df in clone () from /usr/lib/libc.so.6
    No symbol table info available.
    
    Thread 1 (Thread 0x7ffff7fbbe00 (LWP 1034)):
    #0  0x00000000004038a3 in SingleLayerPerceptron::psiClicked (this=<error reading variable: Cannot access memory at address 0x7fffff7f9498>) at ../ANNTeaching/singlelayerperceptron.h:72
            sum1 = 6.9533555994638063e-310
            sum2 = 6.9533491748290073e-310
            error = {6.9533491748290073e-310, 6.9533475108091928e-310}
            d_w0 = {1.6189543082925967e-319, 2.8705214023376424e-321}
            d_w = <error reading variable d_w (value requires 4198400 bytes, which is more than max-value-size)>
    #1  0x0000000000402f0d in SingleLayerPerceptron::qt_static_metacall (_o=0x7fffffbfd410, _c=QMetaObject::InvokeMetaMethod, _id=3, _a=0x7fffffbfa730) at moc_singlelayerperceptron.cpp:102
            _t = 0x7fffffbfd410
    #2  0x00000000004031e1 in SingleLayerPerceptron::qt_metacall (this=0x7fffffbfd410, _c=QMetaObject::InvokeMetaMethod, _id=3, _a=0x7fffffbfa730) at moc_singlelayerperceptron.cpp:165
    No locals.
    #3  0x00007ffff6ccd29c in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #4  0x00007ffff6c5eece in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #5  0x00007ffff6c5f9e6 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #6  0x00007ffff6c603af in QV4::QObjectMethod::callInternal(QV4::CallData*) const () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #7  0x00007ffff6c75f05 in QV4::Runtime::callProperty(QV4::ExecutionEngine*, int, QV4::CallData*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #8  0x00007ffff6c6427d in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #9  0x00007ffff6c65dc2 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #10 0x00007ffff6c0accb in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #11 0x00007ffff6cf5fc2 in QQmlJavaScriptExpression::evaluate(QV4::CallData*, bool*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #12 0x00007ffff6ca0e41 in QQmlBoundSignalExpression::evaluate(void**) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #13 0x00007ffff6ca14cb in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #14 0x00007ffff6cd5cb4 in QQmlNotifier::emitNotify(QQmlNotifierEndpoint*, void**) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #15 0x00007ffff6c84a05 in QQmlData::signalEmitted(QAbstractDeclarativeData*, QObject*, int, void**) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Qml.so.5
    No symbol table info available.
    #16 0x00007ffff6268dc6 in QMetaObject::activate(QObject*, int, int, void**) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #17 0x00007fffe82a7fb8 in QQuickAbstractButton::mouseReleaseEvent(QMouseEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5QuickTemplates2.so.5
    No symbol table info available.
    #18 0x00007ffff797c708 in QQuickItem::event(QEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Quick.so.5
    No symbol table info available.
    #19 0x00007ffff624198a in QCoreApplication::notify(QObject*, QEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #20 0x00007ffff6241ae0 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #21 0x00007ffff798e08a in QQuickWindow::sendEvent(QQuickItem*, QEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Quick.so.5
    No symbol table info available.
    #22 0x00007ffff798e812 in QQuickWindowPrivate::deliverMouseEvent(QMouseEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Quick.so.5
    No symbol table info available.
    #23 0x00007ffff79911f5 in QQuickWindow::mouseReleaseEvent(QMouseEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Quick.so.5
    No symbol table info available.
    #24 0x00007ffff7146f7a in QWindow::event(QEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Gui.so.5
    No symbol table info available.
    #25 0x00007ffff7996e03 in QQuickWindow::event(QEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Quick.so.5
    No symbol table info available.
    #26 0x00007ffff624198a in QCoreApplication::notify(QObject*, QEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #27 0x00007ffff6241ae0 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #28 0x00007ffff713b8db in QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Gui.so.5
    No symbol table info available.
    #29 0x00007ffff713d745 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Gui.so.5
    No symbol table info available.
    #30 0x00007ffff711ee73 in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Gui.so.5
    No symbol table info available.
    #31 0x00007fffef17a080 in ?? () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5XcbQpa.so.5
    No symbol table info available.
    #32 0x00007ffff21dfe67 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #33 0x00007ffff21e00d0 in ?? () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #34 0x00007ffff21e017c in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #35 0x00007ffff628f047 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #36 0x00007ffff623fdca in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #37 0x00007ffff6247bad in QCoreApplication::exec() () from /home/tikani/Qt/5.7/gcc_64/lib/libQt5Core.so.5
    No symbol table info available.
    #38 0x0000000000401dbc in main (argc=1, argv=0x7fffffffe5a8) at ../ANNTeaching/main.cpp:16
            app = <incomplete type>
            engine = <incomplete type>
            neuro = <error reading variable neuro (value of type `SingleLayerPerceptron' requires 4198464 bytes, which is more than max-value-size)>
    

    WHAAT?! 4 Megabytes is more than max value size? I don't use types with a short range of acceptable values. o_O kinda magic....



  • the stack trace is pretty clear: d_w = <error reading variable d_w (value requires 4198400 bytes, which is more than max-value-size)> you cannot allocate such a big array on the stack. use dynamically allocated arrays (new and delete []) or use a more secure class like Boost::multy_array



  • Thanks a lot, I didn't know about stack constraints. Question is closed.


  • Qt Champions 2017

    Good ol' stack overflow. ;P

    @Tikani said in Segfault on invoking Q_INVOKABLE function:

    4 Megabytes is more than max value size?

    Depending on the OS and compiler the stack size will vary between a few hundred kilobytes to the massive 8-16MB range, but very rarely beyond that. I personally think a couple of MB is more than enough, but that's just me. Move your data to the heap just as @VRonin suggested (same for the other function that has the big stack array) and you should be fine.


Log in to reply