go-qml / qml

QML support for the Go language
Other
1.96k stars 187 forks source link

SIGSEGV when changing state property on QML object #84

Closed sountharcs closed 10 years ago

sountharcs commented 10 years ago

i have created qml file with qt creator and it works very well when i run with QtCreator.But it does not run when i use the same qml file with Go. i am getting error like this : SIGSEGV: segmentation violation PC=0xb65dc472 signal arrived during cgo execution Its crashing while i move one rectangle to another rectangle's position. Most of the tutorials are working well even gopher example is working well.
i attached you an example. its working well. But if i use rect1.x and rect1.y instead of 50 & 160 its crashing. So the problem is here. working case :

states: State {
        name: "down";
        PropertyChanges { target: rect1; x:50; y: 160}
    }
crashing :
states: State {
        name: "down";
        PropertyChanges { target: rect1; x:rect2.x; y: rect2.y}
    }

Complete code :

import QtQuick 2.0
Rectangle {
    id: page
    width: 320; height: 480
    color: "lightgray"
    state:"none"
    Rectangle {
        id: rect1
        x: 30
        y: 30
        width:50
        height:50
        MouseArea {
            anchors.fill: parent
            onClicked: page.state = 'down'
        }
    }
    Rectangle {
        id: rect2
        x: 50
        y: 160
        width:50
        height:50
    }
    states: State {
        name: "down";
        PropertyChanges { target: rect1; x:50; y: 160} // if i use rect2.x and rect2.y instead of 50 & 160 its crashing...
    }
    transitions: Transition {
        from: "none"; to: "down";
        NumberAnimation { properties: "x,y"; duration: 2000; easing.type: Easing.InOutQuad }
    }
}
niemeyer commented 10 years ago

This was quickly covered in the mailing list, and I can reproduce the crash. Will have a look after I'm done with the current task.

sountharcs commented 10 years ago

Hi niemeyer, Any update on this issue ! This is also not working. But its working well in QtCreator.

import QtQuick 2.0
Rectangle {
    id: rect
    width: 100; height: 100
    color: "red"
    property bool flag : false
    property int edx: 50
    property int edy: 50
    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: {
            if (flag) {
                rect.state = "moved"
            } else {
                rect.state = "not"
            }
            flag = !flag
        }
    }
    states: [
        State {
            name: "moved";
            PropertyChanges { target: parent; x: edx; y: edy }  // here is problem
        },
        State {
            name: "not";
            PropertyChanges { target: parent; x: 0; y: 0 }
        }
    ]
    transitions: [
        Transition {
            to: "moved"
            NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }
        },
        Transition {
            to: "not"
            NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }
        }
    ]
}
niemeyer commented 10 years ago

Sorry for being slow on this, Sounthar. As you may be following through the list, I've been pushing the GL APIs in the last couple of weeks. I'll stop and look at your case soon.

Please do let me know if you find any other issues meanwhile.

niemeyer commented 10 years ago

So, this is a strange crash. The logic being done by the qml package is not even touching on anything related to the qml file, and the crash happens deep inside Qt itself:

Program received signal SIGSEGV, Segmentation fault.
QV4::FunctionObject::creatScriptFunction (scope=scope@entry=0x7fffe4020500, function=0x0) at jsruntime/qv4functionobject.cpp:187
(gdb) bt
#0  QV4::FunctionObject::creatScriptFunction (scope=scope@entry=0x7fffe4020500, function=0x0) at jsruntime/qv4functionobject.cpp:187
#1  0x00007ffff637ca5b in QQmlBinding::createBinding (id=<optimized out>, obj=0xb516f0, ctxt=ctxt@entry=0xdcb010, url=..., lineNumber=lineNumber@entry=9)
    at qml/qqmlbinding.cpp:95
#2  0x00007ffff6e0204f in QQuickPropertyChanges::actions (this=0x201e1a0) at util/qquickpropertychanges.cpp:482
#3  0x00007ffff6df5500 in QQuickStatePrivate::generateActionList (this=this@entry=0xb51590) at util/qquickstate.cpp:340
#4  0x00007ffff6df5941 in QQuickState::apply (this=this@entry=0xb514e0, trans=trans@entry=0x0, revert=revert@entry=0xb4e200) at util/qquickstate.cpp:579
#5  0x00007ffff6e045bf in QQuickStateGroupPrivate::setCurrentStateInternal (this=0xb51320, state=..., ignoreTrans=ignoreTrans@entry=false) at util/qquickstategroup.cpp:487
#6  0x00007ffff6e04d9b in QQuickStateGroup::setState (this=<optimized out>, state=...) at util/qquickstategroup.cpp:293
#7  0x00007ffff6e7ed75 in QQuickItemPrivate::setState (this=<optimized out>, state=...) at items/qquickitem.cpp:4249
#8  0x00007ffff6e7ed89 in QQuickItem::setState (this=this@entry=0xa885a0, state=...) at items/qquickitem.cpp:4283
#9  0x00007ffff6e8c5f3 in QQuickItem::qt_metacall (this=this@entry=0xa885a0, _c=_c@entry=QMetaObject::WriteProperty, _id=15, _a=_a@entry=0x7fffffffcf20)
    at .moc/moc_qquickitem.cpp:881
#10 0x00007ffff6fa7a57 in QQuickRectangle::qt_metacall (this=0xa885a0, _c=QMetaObject::WriteProperty, _id=<optimized out>, _a=0x7fffffffcf20)
    at .moc/moc_qquickrectangle_p.cpp:556
#11 0x00007ffff62a3e1f in QV4::QObjectWrapper::setProperty (object=0xa885a0, ctx=<optimized out>, property=0x7fffbc038608, value=...) at jsruntime/qv4qobjectwrapper.cpp:535
#12 0x00007ffff62a4265 in QV4::QObjectWrapper::setProperty (this=<optimized out>, ctx=<optimized out>, propertyIndex=<optimized out>, value=...)
    at jsruntime/qv4qobjectwrapper.cpp:646
#13 0x00007ffff62323bf in QV4::__qmljs_set_qobject_property (ctx=<optimized out>, object=..., propertyIndex=<optimized out>, value=...) at jsruntime/qv4runtime.cpp:1319
niemeyer commented 10 years ago

The traceback above was obtained with the stock package from Ubuntu 14.04, Qt 5.2.1.

I have tried to reproduce the problem with a local debug build of Qt 5.2.0 and failed. The example worked fine. I'm now doing a debug build of the upstream Qt 5.2.1 to see if it is reproducible.

niemeyer commented 10 years ago

A few more data points: running the reproducer under the debug build of 5.2.1 5.2.0 (see below) also works fine. Not only that, but while using a single built binary and switching the libraries in use via LD_LIBRARY_PATH between the debug build and the Ubuntu-provided libraries will make the example crash (system libraries) and not crash (debug build).

Update: I misbuilt 5.2.1.. missed the update of the submodules, which means I built 5.2.0 again.

niemeyer commented 10 years ago

So, the debug build of 5.2.0 works fine, but the debug build of 5.2.1 crashes. That's a good lead. Will spend some more time on this next week.

niemeyer commented 10 years ago

Okay, found the problem. It's indeed a bug in Qt, for which I provided a detailed report upstream:

Now let's see how to workaround it so we're not touching the problem.

sountharcs commented 10 years ago

hi Gustavo,

Thanks for your effort to find the issue. lets hope for the best .

On Tue, Sep 9, 2014 at 10:10 AM, Gustavo Niemeyer notifications@github.com wrote:

Okay, found the problem. It's indeed a bug in Qt, for which I provided a detailed report upstream:

Now let's see how to workaround it so we're not touching the problem.

— Reply to this email directly or view it on GitHub https://github.com/go-qml/qml/issues/84#issuecomment-54923562.

niemeyer commented 10 years ago

I will workaround the issue locally in the qml package no matter what, as the upstream fix will not be around for quite some time, even if it lands.