Skip to content

Commit

Permalink
fix crash when using up arrow
Browse files Browse the repository at this point in the history
#0 raise() at /usr/lib/libc.so.6
#1 abort() at /usr/lib/libc.so.6
#2 __assert_fail_base.cold() at /usr/lib/libc.so.6
#3 __assert_fail() at /usr/lib/libc.so.6
#4 DBDataModel::index() at /home/michal/projects/sources/broom/src/gui/desktop/models/db_data_model.cpp:313
#5 QAbstractItemModel::sibling(int, int, QModelIndex const&) const() at /usr/lib/libQt5Core.so.5
#6 QModelIndex::sibling() at /usr/include/qt/QtCore/qabstractitemmodel.h:444
#7 Data::getTopOf() at /home/michal/projects/sources/broom/src/gui/desktop/views/view_impl/data.cpp:359
#8 ImagesTreeView::moveCursor() at /home/michal/projects/sources/broom/src/gui/desktop/views/images_tree_view.cpp:177

Data::getTopOf() was asking for index with negative row (which
is +- ok). DBDataModel::index() was not ready for it.
  • Loading branch information
Kicer86 committed Jun 29, 2019
1 parent a6d3c76 commit 92ca5e2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/gui/desktop/models/db_data_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,23 @@ QVariant DBDataModel::data(const QModelIndex& _index, int role) const

QModelIndex DBDataModel::index(int row, int column, const QModelIndex& _parent) const
{
assert(row >= 0);
const unsigned int urow = static_cast<unsigned int>(row);

QModelIndex idx;
IIdxData* pDataRaw = m_idxDataManager->getIdxDataFor(_parent);

assert(::isNode(pDataRaw));
IdxNodeData* pData = static_cast<IdxNodeData *>(pDataRaw);

if (urow < pData->getChildren().size()) //row out of boundary?
if (column >= 0 && row >= 0)
{
const std::vector<IIdxData::Ptr>& children = pData->getChildren();
IIdxData* cData = children[urow].get();
idx = createIndex(row, column, cData);
const unsigned int urow = static_cast<unsigned int>(row);

IIdxData* pDataRaw = m_idxDataManager->getIdxDataFor(_parent);

assert(::isNode(pDataRaw));
IdxNodeData* pData = static_cast<IdxNodeData *>(pDataRaw);

if (urow < pData->getChildren().size()) //row out of boundary?
{
const std::vector<IIdxData::Ptr>& children = pData->getChildren();
IIdxData* cData = children[urow].get();
idx = createIndex(row, column, cData);
}
}

return idx;
Expand Down

0 comments on commit 92ca5e2

Please sign in to comment.