Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Qt6 crash when dragging rows in table views #4567

Merged
merged 3 commits into from
Apr 21, 2023

Conversation

Nerixyz
Copy link
Contributor

@Nerixyz Nerixyz commented Apr 21, 2023

Description

This PR fixes the crash described in #4563.

I have no clue why the previous code worked in the first place.

  • It's quite clear that both from and to are row-indices:
    int from = data->data("chatterino_row_id").toInt();
    int to = parent.row();
  • QAbstractItemModel::index takes a row, column, and (optional) parent (🤓 actually QAbstractTableModel::index is called, but this doesn't do any fancy things).
  • to is passed at the second argument - in the position of column 💫
    this->moveRow(this->index(from, to), from, parent, to);
  • to isn't a column-index - this won't end well 🤦‍♀️
  • It might happen that the target row index is larger than the amount of columns. In this case, an invalid model-index is returned 🤔
  • This invalid index will eventually be used to look up a row in qt-internals 🕵️‍♂️
  • This returns a null pointer 🙅‍♂️
  • The null pointer will be dereferenced 💥

I changed the column index to 0 which should always be a valid column index. One could also use the column index of parent. But this doesn't really matter since we're moving rows.

Fixes #4563.

@pajlada
Copy link
Member

pajlada commented Apr 21, 2023

Are you able to reproduce this crash on any non-experimental builds?

@Nerixyz
Copy link
Contributor Author

Nerixyz commented Apr 21, 2023

Are you able to reproduce this crash on any non-experimental builds?

No. My guess is that somewhere down the line, the invalid index gets sanitized - or sourceParent wasn't used.

Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Qt5, moving rows outputs this warnings:

QAbstractItemModel::endMoveRows:  Invalid index ( -2 , -1 ) in model QAbstractTableModel(0x555fc51b7070)

With your fix, it no longer outputs those warnings 👍

Other than that, I'd just like the changelog entry changed before merging this in

CHANGELOG.md Outdated Show resolved Hide resolved
@pajlada pajlada changed the title Fix Crash When Dragging Rows in Table-Views Fix Qt6 crash when dragging rows in table views Apr 21, 2023
@pajlada pajlada enabled auto-merge (squash) April 21, 2023 18:04
@pajlada pajlada merged commit 6d2605d into Chatterino:master Apr 21, 2023
15 checks passed
@Nerixyz Nerixyz deleted the fix/highlight-crash branch April 21, 2023 18:31
@KararTY
Copy link
Contributor

KararTY commented Apr 21, 2023

Very poggers my nammer, thank you Nerixyz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Qt6 Chatterino highlight settings menu crash
3 participants