Regression: Qml access to annotations leads to crash
Using the object returned by Segment::qmlAnnotations crashes MuseScore.
I think this was introduced in c14a4e7e
QList qmlAnnotations; foreach (Element* e : _annotations) qmlAnnotations.append(*e); return QQmlListProperty(this, qmlAnnotations);
As described in http://doc.qt.io/qt-5/qqmllistproperty.html#QQmlListProperty, a local variable cannot be used for QQmlListProperty::QQmlListProperty(QObject *object, QList &list):
The list reference must remain valid for as long as object exists.
I consider this of major priority since every plugin that uses the documented annotations property will eventually crash MuseScore.
Comments
I'd just like to add my +1 that this is also causing me problems for a plugin that I'm working on.
See PR 2703 for a possible fix.
Fixed in branch master, commit f4ea58ae84
fix #115971: read-only access to std::vector, QVector and QList properties for qml
Fixed in branch 2.0.4, commit 5aa4cd227a
fix #115971: read-only access to std::vector, QVector and QList properties for qml
Automatically closed -- issue fixed for 2 weeks with no activity.
I'm writing a plugin that needs to read TempoText elements, which I believe should be accessible via Segment.annotations. However, when I try to assign
var x = segment.annotations[0]
where segment.annotations has length 1, MuseScore hangs. Is this another instance of this bug?
I found this big change from 5 months ago which changed how annotations access works -- is this relevant?
https://github.com/musescore/MuseScore/commit/90b1991912d33981dc7bc7d23…
I'm writing a plugin that needs to read TempoText elements, which I believe should be accessible via Segment.annotations. However, when I try to assign
var x = segment.annotations[0]
where segment.annotations has length 1, MuseScore hangs. Is this another instance of this bug?
I found this big change from 5 months ago which changed how annotations access works -- is this relevant?
https://github.com/musescore/MuseScore/commit/90b1991912d33981dc7bc7d23…
@Eric; against which version of MuseScore are you developing your plugin? You can indeed find TempoText elements through segment.annotations and this works for me in all MuseScore 2.x versions, as being used in the TempoChanges plugin.
See https://github.com/jeetee/MuseScore_TempoChanges/blob/master/TempoChang… for the findExistingTempoElement function I've written to detect TempoText elements.
@jeetee: Thanks so much. I'm in version 2.1, but I can't reproduce the crash now, and all seems fine; I think it was a bug elsewhere in my code after all. I can confirm that this is working:
for (var i = 0; i < segment.annotations.length; i++) {
if (segment.annotations[i].type === Element.TEMPO_TEXT) {
console.log("Found TempoText");
console.log(segment.annotations[i].tempo);
console.log(segment.annotations[i].followText);
}
}
Sorry for the false alarm -- and thanks for the link to the TempoChanges plugin; it helped me confirm I wasn't doing something crazy.