Skip to content

Commit

Permalink
Fix light model updates
Browse files Browse the repository at this point in the history
Make sure there is something to remove or add before making
calls to begin/end update methods. Can otherwise lead to
unnecessary updates and potential crashes.

Signed-off-by: Mike Krus <mike.krus@kdab.com>
  • Loading branch information
mkrus authored and nyalldawson committed Apr 27, 2024
1 parent 1b59026 commit 0f9e0cb
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/app/3d/qgslightswidget.cpp
Expand Up @@ -380,24 +380,36 @@ bool QgsLightsModel::removeRows( int row, int count, const QModelIndex &parent )

void QgsLightsModel::setPointLights( const QList<QgsPointLightSettings> &lights )
{
beginRemoveRows( QModelIndex(), 0, mPointLights.size() - 1 );
mPointLights.clear();
endRemoveRows();
if ( !mPointLights.empty() )
{
beginRemoveRows( QModelIndex(), 0, mPointLights.size() - 1 );
mPointLights.clear();
endRemoveRows();
}

beginInsertRows( QModelIndex(), 0, lights.size() - 1 );
mPointLights = lights;
endInsertRows();
if ( !lights.empty() )
{
beginInsertRows( QModelIndex(), 0, lights.size() - 1 );
mPointLights = lights;
endInsertRows();
}
}

void QgsLightsModel::setDirectionalLights( const QList<QgsDirectionalLightSettings> &lights )
{
beginRemoveRows( QModelIndex(), mPointLights.size(), mPointLights.size() + mDirectionalLights.size() - 1 );
mDirectionalLights.clear();
endRemoveRows();
if ( !mDirectionalLights.empty() )
{
beginRemoveRows( QModelIndex(), mPointLights.size(), mPointLights.size() + mDirectionalLights.size() - 1 );
mDirectionalLights.clear();
endRemoveRows();
}

beginInsertRows( QModelIndex(), mPointLights.size(), mPointLights.size() + lights.size() - 1 );
mDirectionalLights = lights;
endInsertRows();
if ( !lights.empty() )
{
beginInsertRows( QModelIndex(), mPointLights.size(), mPointLights.size() + lights.size() - 1 );
mDirectionalLights = lights;
endInsertRows();
}
}

QList<QgsPointLightSettings> QgsLightsModel::pointLights() const
Expand Down

0 comments on commit 0f9e0cb

Please sign in to comment.