Fixed an off-by-one error (two of them actually)

This commit is contained in:
Natty 2023-09-03 01:15:59 +02:00
parent 14e469c139
commit ab7cbc7390
No known key found for this signature in database
GPG key ID: BF6CB659ADEE60EC

View file

@ -23,13 +23,15 @@ function render(users, selfUser) {
const tasks = []; const tasks = [];
totalImg += 1;
remainingImg += 1;
loadImage(ctx, loadImage(ctx,
selfUser.avatar, selfUser.avatar,
(width / 2) - 110, (width / 2) - 110,
(height / 2) - 110, (height / 2) - 110,
110, 110,
"@" + selfUser.handle, "@" + selfUser.handle,
tasks); tasks);
// loop over the layers // loop over the layers
for (let layerIndex= 0; layerIndex < 3; layerIndex++) { for (let layerIndex= 0; layerIndex < 3; layerIndex++) {
@ -37,9 +39,12 @@ tasks);
// loop over each circle of the layer // loop over each circle of the layer
for (let i = 0; i < numb[layerIndex]; i++) { for (let i = 0; i < numb[layerIndex]; i++) {
remainingImg += 1;
// if we are trying to render a circle, but we ran out of users, just exit the loop. We are done. // if we are trying to render a circle, but we ran out of users, just exit the loop. We are done.
if (userNum >= users.length) break; if (userNum >= users.length) break;
totalImg += 1;
remainingImg += 1;
// We need an offset or the first circle will always on the same line, and it looks weird // We need an offset or the first circle will always on the same line, and it looks weird
// Try removing this to see what happens // Try removing this to see what happens
const offset = layerIndex * 30; const offset = layerIndex * 30;
@ -65,8 +70,6 @@ tasks);
} }
} }
totalImg = remainingImg;
ctx.font = "12px sans-serif"; ctx.font = "12px sans-serif";
ctx.fillStyle = "silver"; ctx.fillStyle = "silver";
ctx.fillText("Be gay do crime uwu", 10, 15); ctx.fillText("Be gay do crime uwu", 10, 15);
@ -129,6 +132,7 @@ function loadImage(ctx, url, x, y, r, name, tasks) {
}; };
img.onerror = function() { img.onerror = function() {
console.error(`Error loading image: ${url}}`);
decrementRemaining(); decrementRemaining();
}; };