Skip to content

Commit

Permalink
YACReader: Fix crash when exiting while processing a comic
Browse files Browse the repository at this point in the history
When quitting YACReader while processing a comic, the comic thread needs
to be properly terminated to avoid segfaults and other possible problems.
  • Loading branch information
selmf authored and luisangelsm committed Nov 19, 2022
1 parent 21b8b70 commit 0414104
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Version counting is based on semantic versioning (Major.Feature.Patch)

## WIP

### YACReader
*Fix segfault (or worse) when exiting YACReader while processing a comic
### YACReaderLibrary
* Fixed drag&drop in the comics grid view.
* Detect back/forward mouse buttons to move back and forward through the browsing history.
Expand Down
23 changes: 13 additions & 10 deletions YACReader/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,23 @@ Render::Render()

Render::~Render()
{
if (comic != nullptr) {
comic->moveToThread(QApplication::instance()->thread());
comic->deleteLater();
}

foreach (PageRender *pr, pageRenders)
if (pr != nullptr) {
if (pr->wait())
delete pr;
for (auto *pr : pageRenders) {
if (pr != nullptr && pr->wait()) {
delete pr;
}
}

// TODO move to share_ptr
foreach (ImageFilter *filter, filters)
for (auto *filter : filters) {
delete filter;
}

if (comic != nullptr) {
comic->invalidate();
comic->deleteLater();
comic->thread()->quit();
comic->thread()->wait();
}
}
// Este método se encarga de forzar el renderizado de las páginas.
// Actualiza el buffer según es necesario.
Expand Down
2 changes: 2 additions & 0 deletions common/comic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,10 @@ void PDFComic::renderPage(int page)
#endif
QByteArray ba;
QBuffer buf(&ba);
buf.open(QIODevice::WriteOnly);
img.save(&buf, "jpg", 96);
_pages[page] = ba;
buf.close();
emit imageLoaded(page);
emit imageLoaded(page, _pages[page]);
}
Expand Down

0 comments on commit 0414104

Please sign in to comment.