fixed out of bounds memory access during trapezoid drawing
This commit is contained in:
@@ -168,8 +168,8 @@ namespace UwU {
|
||||
int16_t yGrad[h];
|
||||
|
||||
// calculate gradient coefficients
|
||||
Helpers::bresenham(0, w - 1, 255, xGrad);
|
||||
Helpers::bresenham(0, h - 1, 255, yGrad);
|
||||
Helpers::bresenham(0, 0, w - 1, 255, xGrad);
|
||||
Helpers::bresenham(0, 0, h - 1, 255, yGrad);
|
||||
|
||||
// for each point calculate, alpha blend and print color
|
||||
Color Lmix = Color();
|
||||
@@ -236,10 +236,19 @@ namespace UwU {
|
||||
int16_t LeftBound[height];
|
||||
int16_t RightBound[height];
|
||||
|
||||
Helpers::bresenham(coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound);
|
||||
Helpers::bresenham(coords.xr0, coords.y1 - coords.y0, coords.xr1, RightBound);
|
||||
Helpers::bresenham(0, coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound);
|
||||
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++) {
|
||||
// printf("(%u, %u)", x, i + coords.y0);
|
||||
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.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);
|
||||
|
||||
Reference in New Issue
Block a user