Skip to content

Commit

Permalink
Fix infrequent crash when opening project
Browse files Browse the repository at this point in the history
Model indexes were becoming corrupt if some are processed while the
model is reset.
  • Loading branch information
bmatherly committed Jan 28, 2024
1 parent 6b0308d commit 83187df
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/models/audiolevelstask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ void AudioLevelsTask::run()
p.first->lock();
p.first->set(kAudioLevelsProperty, levelsCopy, 0, (mlt_destructor) deleteQVariantList);
p.first->unlock();
if (-1 != m_object->metaObject()->indexOfMethod("audioLevelsReady(QModelIndex)"))
QMetaObject::invokeMethod(m_object, "audioLevelsReady", Q_ARG(const QModelIndex &, p.second));
if (-1 != m_object->metaObject()->indexOfMethod("audioLevelsReady(QPersistentModelIndex)"))
QMetaObject::invokeMethod(m_object, "audioLevelsReady", Q_ARG(const QPersistentModelIndex &,
p.second));
}
}
}
Expand Down Expand Up @@ -272,8 +273,9 @@ void AudioLevelsTask::run()
p.first->lock();
p.first->set(kAudioLevelsProperty, levelsCopy, 0, (mlt_destructor) deleteQVariantList);
p.first->unlock();
if (-1 != m_object->metaObject()->indexOfMethod("audioLevelsReady(QModelIndex)"))
QMetaObject::invokeMethod(m_object, "audioLevelsReady", Q_ARG(const QModelIndex &, p.second));
if (-1 != m_object->metaObject()->indexOfMethod("audioLevelsReady(QPersistentModelIndex)"))
QMetaObject::invokeMethod(m_object, "audioLevelsReady", Q_ARG(const QPersistentModelIndex &,
p.second));
}
}
}
4 changes: 3 additions & 1 deletion src/models/multitrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ void MultitrackModel::consolidateBlanksAllTracks()
}
}

void MultitrackModel::audioLevelsReady(const QModelIndex &index)
void MultitrackModel::audioLevelsReady(const QPersistentModelIndex &index)
{
QVector<int> roles;
roles << AudioLevelsRole;
Expand Down Expand Up @@ -3360,6 +3360,7 @@ int MultitrackModel::getDuration()
void MultitrackModel::load()
{
if (m_tractor) {
AudioLevelsTask::closeAll();
beginResetModel();
delete m_tractor;
m_tractor = 0;
Expand Down Expand Up @@ -3404,6 +3405,7 @@ void MultitrackModel::reload(bool asynchronous)
if (asynchronous) {
emit reloadRequested();
} else {
AudioLevelsTask::closeAll();
beginResetModel();
endResetModel();
getAudioLevels();
Expand Down
2 changes: 1 addition & 1 deletion src/models/multitrackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MultitrackModel : public QAbstractItemModel
QModelIndex makeIndex(int trackIndex, int clipIndex) const;
QModelIndex parent(const QModelIndex &index) const;
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE void audioLevelsReady(const QModelIndex &index);
Q_INVOKABLE void audioLevelsReady(const QPersistentModelIndex &index);
bool createIfNeeded();
void addBackgroundTrack();
int addAudioTrack();
Expand Down
2 changes: 1 addition & 1 deletion src/qmltypes/qmlproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void QmlProducer::launchGlaxnimate(const QString &filename) const
}
}

void QmlProducer::audioLevelsReady(const QModelIndex &index)
void QmlProducer::audioLevelsReady(const QPersistentModelIndex &index)
{
Q_UNUSED(index)
emit audioLevelsChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/qmltypes/qmlproducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class QmlProducer : public QObject
{
return m_producer;
}
Q_INVOKABLE void audioLevelsReady(const QModelIndex &index);
Q_INVOKABLE void audioLevelsReady(const QPersistentModelIndex &index);
Q_INVOKABLE void remakeAudioLevels();
double displayAspectRatio();
Q_INVOKABLE QString get(QString name, int position = -1);
Expand Down

0 comments on commit 83187df

Please sign in to comment.