From 0a4bafdc75ef094f2b6d55d97b18eae8df7db151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 6 Jun 2024 14:52:01 -0300 Subject: [PATCH] FileSystemModel: Crash fix on invalid file event. --- include/eepp/ui/models/model.hpp | 4 ++-- src/eepp/ui/models/filesystemmodel.cpp | 11 +++++----- src/eepp/ui/models/model.cpp | 28 +++++++++++++------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/include/eepp/ui/models/model.hpp b/include/eepp/ui/models/model.hpp index 1b5d6d1a1..1f20e6c05 100644 --- a/include/eepp/ui/models/model.hpp +++ b/include/eepp/ui/models/model.hpp @@ -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(); diff --git a/src/eepp/ui/models/filesystemmodel.cpp b/src/eepp/ui/models/filesystemmodel.cpp index ebaf8967e..4ceb4d7d0 100644 --- a/src/eepp/ui/models/filesystemmodel.cpp +++ b/src/eepp/ui/models/filesystemmodel.cpp @@ -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 newIndexes; diff --git a/src/eepp/ui/models/model.cpp b/src/eepp/ui/models/model.cpp index b9030c836..e64b6933c 100644 --- a/src/eepp/ui/models/model.cpp +++ b/src/eepp/ui/models/model.cpp @@ -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( 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( 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( 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( parent, first, last ); + mOperationStack.push( { OperationType::Delete, Direction::Column, parent, first, last } ); + return true; + } + return false; } std::weak_ptr Model::registerPersistentIndex( ModelIndex const& index ) {