-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #27201 - PLUGINS: methods returning pntrs to QObject lead to crash. #1028
Fix #27201 - PLUGINS: methods returning pntrs to QObject lead to crash. #1028
Conversation
For details, including an analysis of the problem, see http://musescore.org/en/node/27201 This fix only covers `Q_INVOKABLE` methods in the `Note` class; there are probably more of them on other classes.
@@ -2327,5 +2327,17 @@ NoteVal Note::noteVal() const | |||
return nval; | |||
} | |||
|
|||
} | |||
//--------------------------------------------------------- | |||
// noteVal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here, should be qmlDots.
Except this, it's a wonderful analysis! Thank you for doing it!
Thanks for spotting the typos. This is a potentially exhaustive list of Q_INVOKABLE methods returning pointers to objects derived from QObject in the various classes. It has been made by searching for "Q_INVOKABLE Ms::" in .h files:
Q_INVOKABLE Ms::Note* addNote(int pitch)
Q_INVOKABLE Ms::FiguredBassItem* addItem()
Q_INVOKABLE Ms::Segment* first()
Q_INVOKABLE Ms::Measure* nextMeasure()
Q_INVOKABLE Ms::Measure* firstMeasure()
Q_INVOKABLE Ms::Segment* next() I think all of them should be converted into properties or, in some way, given a C++ ownership, as the returned element should not be garbage collected. Probably, Cursor::addNote() and FiguredBass::addItem() should be removed and replaced by some usage of QmlPlugin::newElement() (the last one is a temporary hack anyway...). I am not sure what to do about the following in mscore/qmlplugin.h: Lastly, in libmscore/score.h: Shall I go on and change at least the first group? |
Sure, go ahead and fix the more obvious. While converting them, I would give next1 and next proper names... Also prev/nextMeasure should probably call their MM counterpart from a plugin perspective... or we could expose both. |
About the documentation in
should probably read: A) or maybe with pattern: B) for properties with a large number of retuned values, which would result in over-long lines with the A) pattern. Am I missing something? Comments? |
…ng them into a property: - Measure: -- firstSegment -- lastSegment - MeasureBase: -- nextMeasure -- nextMeasureMM (new) -- prevMeasure -- prevMeasureMM (new) - Score: -- firstMeasure -- firstMeasureMM (new) -- (for firstSegment(), see special cases below) -- lastMeasure -- lastMeasureMM (new) -- lastSegment - Segment: -- next (renamed from `next1`) -- nextInMeasure (renamed from `next`) -- prev (renamed from `prev1`) -- prevInMeasure (renamed from prev) Special cases: - Cursor: The prototype of the `Q_INVOKABLE Ms::Note* Cursor::addNote(int pitch)` was wrong: corrected in `Q_INVOKABLE void Cursor::addNote(int pitch)`. - QmlPlugin: `Q_INVOKABLE Score* QmlPlugin::readScore()` and `Q_INVOKABLE Score* QmlPlugin::newScore()` has been kept, as they are intended to be called from QML; code has been added to ensure the C++ ownership of the returned object. - Score: `Q_INVOKABLE Segment* Score::firstSegment(Segment::Type segType)` is kept (as it needs a parameters), but code is added to ensure C++ ownership of the returned Segment*. - Segment: `Ms::Element* Segment::element(int track)` has been made NOT Q_INVOKABLE; a variant `Q_INVOKABLE Ms::Element* elementAt(int track)` has been added specifically for QML with code to ensure the C++ ownership of the returned Element* (this was the cause for the crash of the Walk plug-in). - FiguredBass: `Q_INVOKABLE Ms::FiguredBassItem* FiguredBass::addItem()` has been removed; plugin interface for FiguredBass needs to be redesigned anyway. The few occurrences in the supplied plug-ins of the methods whose names did change have been updated.
See http://musescore.org/en/node/26796, it does request e better method to document enums for plugins |
I put in the Ms:: in the hope of this making the hyperlinks in the documentation work |
…ning_QObjects Fix #27201 - PLUGINS: methods returning pntrs to QObject lead to crash.
Fix #27201 - PLUGINS: methods returning pntrs to QObject lead to crash.
For details, including an analysis of the problem, see http://musescore.org/en/node/27201
Fixes the following Q_INVOKABLE methods returning a QObject* by turning them into a property:
next1
)next
)prev1
)prev
)Special cases:
Q_INVOKABLE Ms::Note* Cursor::addNote(int pitch)
was wrong: corrected inQ_INVOKABLE void Cursor::addNote(int pitch)
.Q_INVOKABLE Score* QmlPlugin::readScore()
andQ_INVOKABLE Score* QmlPlugin::newScore()
has been kept, as they are intended to be called from QML; code has been added to ensure the C++ ownership of the returned object.Q_INVOKABLE Segment* Score::firstSegment(Segment::Type segType)
is kept (as it needs a parameters), but code is added to ensure C++ ownership of the returned Segment*.Ms::Element* Segment::element(int track)
has been made NOT Q_INVOKABLE; a variantQ_INVOKABLE Ms::Element* elementAt(int track)
has been added specifically for QML with code to ensure the C++ ownership of the returned Element* (this was the cause for the crash of the Walk plug-in).Q_INVOKABLE Ms::FiguredBassItem* FiguredBass::addItem()
has been removed; plugin interface for FiguredBass needs to be redesigned anyway.The few occurrences in the supplied plug-ins of the methods whose names did change have been updated.