Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

Commit

Permalink
fix(Index Out Of Bounds Exception): Only draw if the calculated eleme…
Browse files Browse the repository at this point in the history
…nt is within the number of elements when drawing Kitt rectangles
  • Loading branch information
Griefed committed Jun 14, 2022
1 parent 37ec641 commit 22b4168
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/main/java/de/griefed/larsonscanner/LarsonScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2376,12 +2376,14 @@ private void drawKittRect(@NotNull Graphics2D g2d, byte startY) {
*/
elementToDraw = (byte) (numberOfElements - (drawnElementsWidth / elementWidth) - 1);

if (useGradients) {
g2d.setPaint(kittRectGradient(elementToDraw, getCenter(0)));
} else {
g2d.setColor(eyeColours[elementToDraw]);
if (elementToDraw < numberOfElements) {
if (useGradients) {
g2d.setPaint(kittRectGradient(elementToDraw, getCenter(0)));
} else {
g2d.setColor(eyeColours[elementToDraw]);
}
g2d.fillRect(0, startY, (int) elementWidth, (int) height);
}
g2d.fillRect(0, startY, (int) elementWidth, (int) height);
}

} else {
Expand Down Expand Up @@ -2410,12 +2412,14 @@ private void drawKittRect(@NotNull Graphics2D g2d, byte startY) {
elementToDraw =
(byte) (numberOfElements - ((width - drawnElementsWidth) / elementWidth) - 1);

if (useGradients) {
g2d.setPaint(kittRectGradient(elementToDraw, getCenter(startOfElement)));
} else {
g2d.setColor(eyeColours[elementToDraw]);
if (elementToDraw < numberOfElements) {
if (useGradients) {
g2d.setPaint(kittRectGradient(elementToDraw, getCenter(startOfElement)));
} else {
g2d.setColor(eyeColours[elementToDraw]);
}
g2d.fillRect((int) startOfElement, startY, (int) elementWidth, (int) height);
}
g2d.fillRect((int) startOfElement, startY, (int) elementWidth, (int) height);
}
}
}
Expand Down

0 comments on commit 22b4168

Please sign in to comment.