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

Delete timeline causes crash on Windows #680

Closed
wolfseifert opened this issue Jan 2, 2024 · 7 comments
Closed

Delete timeline causes crash on Windows #680

wolfseifert opened this issue Jan 2, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@wolfseifert
Copy link
Contributor

The following code line

connect(timeline, &QTimeLine::finished, [timeline] { delete timeline; });

in ui/RepoView.cpp:893 (same in ui/MainWindow.cpp:204) causes my private fork of Gittyup to crash on Windows. The timeline is accessed after deletion and has therefore invalid pointer values.

Here is a short reproducer:

#include <QtWidgets>

auto main(int argc, char* argv[]) -> int {
  auto app = QApplication{argc, argv};
  auto win = QMainWindow{};
  auto progressBar = new QProgressBar{};
  progressBar->setRange(0, 100);

  auto timeLine = new QTimeLine{1000, &win};
  timeLine->setFrameRange(0, 100);
  win.connect(timeLine, &QTimeLine::frameChanged, progressBar, &QProgressBar::setValue);
  win.connect(timeLine, &QTimeLine::finished, [timeLine] {
    delete timeLine;
  });
  timeLine->start();

  win.setCentralWidget(progressBar);
  win.show();
  return QApplication::exec();
}

Fix: Remove these lines!

@Murmele
Copy link
Owner

Murmele commented Feb 6, 2024

Maybe using deleteLater() instead

@Murmele Murmele added the bug Something isn't working label Feb 6, 2024
@wolfseifert
Copy link
Contributor Author

Maybe this will prevent the crash, maybe not. The delete timeLine already happens on the main-thread, so deleteLater could happen instantly.

I found nothing in the Qt-Assistant about explicitly deleting a created QTimeLine, so doing nothing (i.e. removing the two lines of code mentioned above) is probably the better option. Better to have a (small) memory leak than an application crash.

@Murmele
Copy link
Owner

Murmele commented Feb 7, 2024

Are you able to reproduce the crash? Can you try out with deleteLater?

@wolfseifert
Copy link
Contributor Author

I already tried it before my last comment:

It does not happen with deleteLate on windows, it never happenes on linux!

But as long as I can not find a hint in the documentation when to delete QTimeLine safely, I would be cautious and just don't do it!

@wolfseifert
Copy link
Contributor Author

A debug session later:

The line with delete timeLine; is done during timer-event handling, which causes a crash when going back up the stack.

Replacing it with timeLine.deleteLater(); during the timer-event handling, the stack is upwinded successfully (because the timeLine has not been deleted yet) and the the actual delete timeLine; happens on another deferred-deletion-event handling.

So this works. Unfortunately I could not find any documentation on this ("How to delete safely a QTimeLine") .

@Murmele
Copy link
Owner

Murmele commented Feb 7, 2024

Thanks for testing! Maybe it can be handled as any other QObject and therefore deleteLater() works fine. Neverthless I wanna get rid of the memory instead of having a memory leakage. Can you make a pull request?

wolfseifert added a commit to wolfseifert/Gittyup that referenced this issue Feb 8, 2024
delete-timeline-causes-crash-on-windows-Murmele#680
wolfseifert added a commit to wolfseifert/Gittyup that referenced this issue Feb 8, 2024
delete-timeline-causes-crash-on-windows-Murmele#680
Murmele added a commit that referenced this issue Feb 20, 2024
…-on-windows-#680

Delete timeline causes crash on windows #680
@Murmele
Copy link
Owner

Murmele commented Feb 20, 2024

fixed with #693

@Murmele Murmele closed this as completed Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants