mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 23:17:21 -06:00
- BUGFIX: Fix crash with downloaded/availability bars when the torrent has too many pieces
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - 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 <chris@qbittorrent.org> - v2.0.4
|
||||
- BUGFIX: Fix PeerGuardian .p2b binary filter support
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <QList>
|
||||
#include <QPixmap>
|
||||
#include <libtorrent/bitfield.hpp>
|
||||
#include <math.h>
|
||||
|
||||
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<pieces.size(); ++i) {
|
||||
if(pieces[i])
|
||||
painter.setPen(Qt::blue);
|
||||
else
|
||||
painter.setPen(Qt::white);
|
||||
painter.drawPoint(i,0);
|
||||
int nb_pieces = pieces.size();
|
||||
// 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());
|
||||
QVector<bool> scaled_pieces;
|
||||
for(int i=0; i<nb_pieces; i+= ratio) {
|
||||
bool have = true;
|
||||
for(int j=i; j<qMin(i+ratio, nb_pieces); ++j) {
|
||||
if(!pieces[i]) { have = false; break; }
|
||||
}
|
||||
scaled_pieces << have;
|
||||
}
|
||||
QPixmap pix = QPixmap(scaled_pieces.size(), 1);
|
||||
pix.fill();
|
||||
QPainter painter(&pix);
|
||||
for(int i=0; i<scaled_pieces.size(); ++i) {
|
||||
if(scaled_pieces[i])
|
||||
painter.setPen(Qt::blue);
|
||||
else
|
||||
painter.setPen(Qt::white);
|
||||
painter.drawPoint(i,0);
|
||||
}
|
||||
pixmap = pix;
|
||||
} else {
|
||||
QPixmap pix = QPixmap(pieces.size(), 1);
|
||||
pix.fill();
|
||||
QPainter painter(&pix);
|
||||
for(uint i=0; i<pieces.size(); ++i) {
|
||||
if(pieces[i])
|
||||
painter.setPen(Qt::blue);
|
||||
else
|
||||
painter.setPen(Qt::white);
|
||||
painter.drawPoint(i,0);
|
||||
}
|
||||
pixmap = pix;
|
||||
}
|
||||
pixmap = pix;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <QPixmap>
|
||||
#include <QColor>
|
||||
#include <numeric>
|
||||
#include <math.h>
|
||||
|
||||
#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<int>::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<int> scaled_avail;
|
||||
for(int i=0; i<nb_pieces; i+= ratio) {
|
||||
int j = i;
|
||||
int sum = avail[i];
|
||||
for(j=i+1; j<qMin(i+ratio, nb_pieces); ++j) {
|
||||
sum += avail[j];
|
||||
}
|
||||
scaled_avail.push_back(sum/(qMin(ratio, nb_pieces-i)));
|
||||
}
|
||||
QPixmap pix = QPixmap(scaled_avail.size(), 1);
|
||||
pix.fill();
|
||||
QPainter painter(&pix);
|
||||
for(qulonglong i=0; i < scaled_avail.size(); ++i) {
|
||||
painter.setPen(getPieceColor(scaled_avail[i], average));
|
||||
painter.drawPoint(i,0);
|
||||
}
|
||||
pixmap = pix;
|
||||
} else {
|
||||
QPixmap pix = QPixmap(nb_pieces, 1);
|
||||
pix.fill();
|
||||
QPainter painter(&pix);
|
||||
for(int i=0; i < nb_pieces; ++i) {
|
||||
painter.setPen(getPieceColor(avail[i], average));
|
||||
painter.drawPoint(i,0);
|
||||
}
|
||||
pixmap = pix;
|
||||
}
|
||||
pixmap = pix;
|
||||
}
|
||||
update();
|
||||
return average;
|
||||
|
||||
Reference in New Issue
Block a user