Skip to content

Commit

Permalink
Merge pull request #5672 from dmitrio95/289643-volta-anchor-read
Browse files Browse the repository at this point in the history
fix #289643: fix crashes if volta anchor is set incorrectly in MSCZ file
  • Loading branch information
dmitrio95 committed Mar 10, 2020
2 parents 78e0f09 + f97cfd1 commit 72378da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 21 additions & 3 deletions libmscore/volta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Volta::Volta(Score* s)
resetProperty(Pid::BEGIN_HOOK_TYPE);
resetProperty(Pid::END_HOOK_TYPE);

setAnchor(Anchor::MEASURE);
setAnchor(VOLTA_ANCHOR);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -138,11 +138,29 @@ void Volta::read(XmlReader& e)
_endings.append(i);
}
}
else if (!TextLineBase::readProperties(e))
else if (!readProperties(e))
e.unknown();
}
}

//---------------------------------------------------------
// readProperties
//---------------------------------------------------------

bool Volta::readProperties(XmlReader& e)
{
if (!TextLineBase::readProperties(e))
return false;

if (anchor() != VOLTA_ANCHOR) {
// Volta strictly assumes that its anchor is measure, so don't let old scores override this.
qWarning("Correcting volta anchor type from %d to %d", int(anchor()), int(VOLTA_ANCHOR));
setAnchor(VOLTA_ANCHOR);
}

return true;
}

//---------------------------------------------------------
// write
//---------------------------------------------------------
Expand Down Expand Up @@ -246,7 +264,7 @@ QVariant Volta::propertyDefault(Pid propertyId) const
case Pid::VOLTA_ENDING:
return QVariant::fromValue(QList<int>());
case Pid::ANCHOR:
return int(Anchor::MEASURE);
return int(VOLTA_ANCHOR);
case Pid::BEGIN_HOOK_TYPE:
return int(HookType::HOOK_90);
case Pid::END_HOOK_TYPE:
Expand Down
2 changes: 2 additions & 0 deletions libmscore/volta.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class VoltaSegment final : public TextLineBaseSegment {

class Volta final : public TextLineBase {
QList<int> _endings;
static constexpr Anchor VOLTA_ANCHOR = Anchor::MEASURE;

public:
enum class Type : char {
Expand All @@ -60,6 +61,7 @@ class Volta final : public TextLineBase {

virtual void write(XmlWriter&) const override;
virtual void read(XmlReader& e) override;
bool readProperties(XmlReader&) override;
virtual SpannerSegment* layoutSystem(System* system) override;

void setVelocity() const;
Expand Down

0 comments on commit 72378da

Please sign in to comment.