diff --git a/Changelog b/Changelog index 7804eb8de..f73a07d74 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,5 @@ * Unreleased - Christophe Dumez - v2.0.5 - - BUGFIX: Fix possible crash when drawing piece downloaded/availability bars + - BUGFIX: Fix crash with downloaded/availability bars when the torrent has too many pieces * Wed Dec 30 2009 - Christophe Dumez - v2.0.4 - BUGFIX: Fix PeerGuardian .p2b binary filter support diff --git a/src/downloadedpiecesbar.h b/src/downloadedpiecesbar.h index 6f4788b66..9dba245c6 100644 --- a/src/downloadedpiecesbar.h +++ b/src/downloadedpiecesbar.h @@ -36,6 +36,7 @@ #include #include #include +#include using namespace libtorrent; #define BAR_HEIGHT 18 @@ -59,17 +60,43 @@ public: pix.fill(); pixmap = pix; } else { - QPixmap pix = QPixmap(pieces.size(), 1); - pix.fill(); - QPainter painter(&pix); - for(uint i=0; i width()) { + int ratio = floor(nb_pieces/(double)width()); + QVector scaled_pieces; + for(int i=0; i #include #include +#include #define BAR_HEIGHT 18 @@ -59,17 +60,39 @@ public: pixmap = pix; } else { // Look for maximum value - average = std::accumulate(avail.begin(), avail.end(), 0)/(double)avail.size(); - uint nb_pieces = avail.size(); - QPixmap pix = QPixmap(nb_pieces, 1); - pix.fill(); - QPainter painter(&pix); - std::vector::iterator it; - for(uint i=0; i < nb_pieces; ++i) { - painter.setPen(getPieceColor(avail[i], average)); - painter.drawPoint(i,0); + int nb_pieces = avail.size(); + average = std::accumulate(avail.begin(), avail.end(), 0)/(double)nb_pieces; + // Reduce the number of pieces before creating the pixmap + // otherwise it can crash when there are too many pieces + if(nb_pieces > width()) { + int ratio = floor(nb_pieces/(double)width()); + std::vector scaled_avail; + for(int i=0; i