fixed out of bounds memory access during trapezoid drawing

This commit is contained in:
2026-07-05 20:23:51 -07:00
parent b73c25a4fd
commit e4febca4bd
2 changed files with 15 additions and 6 deletions
BIN
View File
Binary file not shown.
+15 -6
View File
@@ -168,8 +168,8 @@ namespace UwU {
int16_t yGrad[h]; int16_t yGrad[h];
// calculate gradient coefficients // calculate gradient coefficients
Helpers::bresenham(0, w - 1, 255, xGrad); Helpers::bresenham(0, 0, w - 1, 255, xGrad);
Helpers::bresenham(0, h - 1, 255, yGrad); Helpers::bresenham(0, 0, h - 1, 255, yGrad);
// for each point calculate, alpha blend and print color // for each point calculate, alpha blend and print color
Color Lmix = Color(); Color Lmix = Color();
@@ -236,10 +236,19 @@ namespace UwU {
int16_t LeftBound[height]; int16_t LeftBound[height];
int16_t RightBound[height]; int16_t RightBound[height];
Helpers::bresenham(coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound); Helpers::bresenham(0, coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound);
Helpers::bresenham(coords.xr0, coords.y1 - coords.y0, coords.xr1, RightBound); Helpers::bresenham(0, coords.xr0, coords.y1 - coords.y0, coords.xr1, RightBound);
for (uint16_t i = 0; i <= height; i++) { printf("leftbound\n");
for (uint16_t i = 0; i < height; i++) {
printf("(%u, %u)\n", i, LeftBound[i]);
}
printf("rightbound\n");
for (uint16_t i = 0; i < height; i++) {
printf("(%u, %u)\n", i, RightBound[i]);
}
for (uint16_t i = 0; i < height; i++) {
for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) { for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) {
// printf("(%u, %u)", x, i + coords.y0); // printf("(%u, %u)", x, i + coords.y0);
putPixel((uint32_t)x, (uint32_t)i + coords.y0, color.r, color.g, color.b, color.a); putPixel((uint32_t)x, (uint32_t)i + coords.y0, color.r, color.g, color.b, color.a);
@@ -364,7 +373,7 @@ int main(void) {
draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red); draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red);
draw.trapezoid(UwU::Trapezoid(300, 400, 360, 380, 600, 400), green); draw.trapezoid(UwU::Trapezoid(300, 400, 360, 380, 600, 400), green);
draw.triangle(UwU::Triangle(200, 100, 240, 200, 320, 300), green); draw.triangle(UwU::Triangle(200, 100, 240, 300, 320, 300), green);
draw.point(UwU::Coord2(387, 43), green); draw.point(UwU::Coord2(387, 43), green);