FileSystemModel: Crash fix on invalid file event.

This commit is contained in:
Martín Lucas Golini
2024-06-06 14:52:01 -03:00
parent 3654c2d3ef
commit 0a4bafdc75
3 changed files with 21 additions and 22 deletions

View File

@@ -134,8 +134,8 @@ class EE_API Model {
ModelIndex const& targetParent, int target_index );
void beginMoveColumns( ModelIndex const& sourceParent, int first, int last,
ModelIndex const& targetParent, int target_index );
void beginDeleteRows( ModelIndex const& parent, int first, int last );
void beginDeleteColumns( ModelIndex const& parent, int first, int last );
bool beginDeleteRows( ModelIndex const& parent, int first, int last );
bool beginDeleteColumns( ModelIndex const& parent, int first, int last );
void endInsertRows();
void endInsertColumns();

View File

@@ -678,12 +678,11 @@ bool FileSystemModel::handleFileEventLocked( const FileEvent& event ) {
} );
} );
beginDeleteRows( index.parent(), index.row(), index.row() );
eeDelete( parent->mChildren[index.row()] );
parent->mChildren.erase( parent->mChildren.begin() + index.row() );
endDeleteRows();
if ( beginDeleteRows( index.parent(), index.row(), index.row() ) ) {
eeDelete( parent->mChildren[index.row()] );
parent->mChildren.erase( parent->mChildren.begin() + index.row() );
endDeleteRows();
}
forEachView( [&]( UIAbstractView* view ) {
std::vector<ModelIndex> newIndexes;

View File

@@ -93,22 +93,22 @@ void Model::beginMoveColumns( ModelIndex const& sourceParent, int first, int las
targetParent, targetIndex } );
}
void Model::beginDeleteRows( ModelIndex const& parent, int first, int last ) {
eeASSERT( first >= 0 );
eeASSERT( first <= last );
eeASSERT( (size_t)last < rowCount( parent ) );
saveDeletedIndices<true>( parent, first, last );
mOperationStack.push( { OperationType::Delete, Direction::Row, parent, first, last } );
bool Model::beginDeleteRows( ModelIndex const& parent, int first, int last ) {
if ( first >= 0 && first <= last && (size_t)last < rowCount( parent ) ) {
saveDeletedIndices<true>( parent, first, last );
mOperationStack.push( { OperationType::Delete, Direction::Row, parent, first, last } );
return true;
}
return false;
}
void Model::beginDeleteColumns( ModelIndex const& parent, int first, int last ) {
eeASSERT( first >= 0 );
eeASSERT( first <= last );
eeASSERT( (size_t)last < columnCount( parent ) );
saveDeletedIndices<false>( parent, first, last );
mOperationStack.push( { OperationType::Delete, Direction::Column, parent, first, last } );
bool Model::beginDeleteColumns( ModelIndex const& parent, int first, int last ) {
if ( first >= 0 && first <= last && (size_t)last < columnCount( parent ) ) {
saveDeletedIndices<false>( parent, first, last );
mOperationStack.push( { OperationType::Delete, Direction::Column, parent, first, last } );
return true;
}
return false;
}
std::weak_ptr<PersistentHandle> Model::registerPersistentIndex( ModelIndex const& index ) {