mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00:00
- Fix crash in pieces downloaded/availability bars when the torrent has too many pieces
This commit is contained in:
parent
6d88bb5b83
commit
b87a23037e
@ -36,6 +36,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <libtorrent/bitfield.hpp>
|
#include <libtorrent/bitfield.hpp>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
#define BAR_HEIGHT 18
|
#define BAR_HEIGHT 18
|
||||||
@ -59,17 +60,43 @@ public:
|
|||||||
pix.fill();
|
pix.fill();
|
||||||
pixmap = pix;
|
pixmap = pix;
|
||||||
} else {
|
} else {
|
||||||
QPixmap pix = QPixmap(pieces.size(), 1);
|
int nb_pieces = pieces.size();
|
||||||
pix.fill();
|
// Reduce the number of pieces before creating the pixmap
|
||||||
QPainter painter(&pix);
|
// otherwise it can crash when there are too many pieces
|
||||||
for(uint i=0; i<pieces.size(); ++i) {
|
if(nb_pieces > width()) {
|
||||||
if(pieces[i])
|
int ratio = floor(nb_pieces/(double)width());
|
||||||
painter.setPen(Qt::blue);
|
QVector<bool> scaled_pieces;
|
||||||
else
|
for(int i=0; i<nb_pieces; i+= ratio) {
|
||||||
painter.setPen(Qt::white);
|
bool have = true;
|
||||||
painter.drawPoint(i,0);
|
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();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define BAR_HEIGHT 18
|
#define BAR_HEIGHT 18
|
||||||
|
|
||||||
@ -59,17 +60,39 @@ public:
|
|||||||
pixmap = pix;
|
pixmap = pix;
|
||||||
} else {
|
} else {
|
||||||
// Look for maximum value
|
// Look for maximum value
|
||||||
uint nb_pieces = avail.size();
|
int nb_pieces = avail.size();
|
||||||
average = std::accumulate(avail.begin(), avail.end(), 0)/(double)nb_pieces;
|
average = std::accumulate(avail.begin(), avail.end(), 0)/(double)nb_pieces;
|
||||||
QPixmap pix = QPixmap(nb_pieces, 1);
|
// Reduce the number of pieces before creating the pixmap
|
||||||
pix.fill();
|
// otherwise it can crash when there are too many pieces
|
||||||
QPainter painter(&pix);
|
if(nb_pieces > width()) {
|
||||||
std::vector<int>::iterator it;
|
int ratio = floor(nb_pieces/(double)width());
|
||||||
for(uint i=0; i < nb_pieces; ++i) {
|
std::vector<int> scaled_avail;
|
||||||
painter.setPen(getPieceColor(avail[i], average));
|
for(int i=0; i<nb_pieces; i+= ratio) {
|
||||||
painter.drawPoint(i,0);
|
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();
|
update();
|
||||||
return average;
|
return average;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user