Skip to content

Commit

Permalink
Fixed a couple of crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereverzev committed Mar 2, 2022
1 parent f6ae8b0 commit 74e962f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/context/internal/globalcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Notification GlobalContext::currentMasterNotationChanged() const

void GlobalContext::setCurrentNotation(const INotationPtr& notation)
{
if (m_currentNotation == notation) {
return;
}

doSetCurrentNotation(notation);
m_currentNotationChanged.notify();
}
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,11 @@ Measure* Score::crMeasure(int idx) const
Measure* Score::lastMeasure() const
{
MeasureBase* mb = _measures.last();

if (!mb) {
return nullptr;
}

while (mb && mb->type() != ElementType::MEASURE) {
mb = mb->prev();
}
Expand Down
11 changes: 10 additions & 1 deletion src/engraving/playback/playbackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const InstrumentTrackId PlaybackModel::METRONOME_TRACK_ID = { 999, METRONOME_INS

void PlaybackModel::load(Ms::Score* score, async::Channel<int, int, int, int> notationChangesRangeChannel)
{
if (!score || score->measures()->empty()) {
if (!score || score->measures()->empty() || !score->lastMeasure()) {
return;
}

Expand Down Expand Up @@ -164,6 +164,11 @@ void PlaybackModel::updateSetupData()
for (const Ms::Part* part : m_score->parts()) {
for (const auto& pair : *part->instruments()) {
InstrumentTrackId trackId = idKey(part->id(), pair.second->id().toStdString());

if (!trackId.isValid()) {
continue;
}

m_setupResolver.resolveSetupData(pair.second, m_playbackDataMap[std::move(trackId)].setupData);
}
}
Expand Down Expand Up @@ -211,6 +216,10 @@ void PlaybackModel::updateEvents(const int tickFrom, const int tickTo, const int

InstrumentTrackId trackId = idKey(item);

if (!trackId.isValid()) {
continue;
}

PlaybackContext& ctx = m_playbackCtxMap[trackId];
ctx.update(segment, segmentPositionTick);

Expand Down
5 changes: 5 additions & 0 deletions src/engraving/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ struct InstrumentTrackId {

return instrumentId < other.instrumentId;
}

bool isValid() const
{
return partId.isValid() && !instrumentId.empty();
}
};

using InstrumentTrackIdSet = std::unordered_set<InstrumentTrackId>;
Expand Down
5 changes: 5 additions & 0 deletions src/playback/internal/playbackcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ void PlaybackController::addTrack(const InstrumentTrackId& instrumentTrackId, co
IF_ASSERT_FAILED(notationPlayback() && playback()) {
return;
}

if (!instrumentTrackId.isValid()) {
return;
}

AudioInputParams inParams = audioSettings()->trackInputParams(instrumentTrackId);
AudioOutputParams outParams = trackOutputParams(instrumentTrackId);
mpe::PlaybackData playbackData = notationPlayback()->trackPlaybackData(instrumentTrackId);
Expand Down

0 comments on commit 74e962f

Please sign in to comment.