Bläddra i källkod

fixed out of bounds error

subDesTagesMitExtraKaese 3 år sedan
förälder
incheckning
8520452729
1 ändrade filer med 4 tillägg och 0 borttagningar
  1. 4 0
      software/Pong_Code/Display.h

+ 4 - 0
software/Pong_Code/Display.h

@@ -83,6 +83,10 @@ void draw_console() {
  * x and y are the coordinates, x is collumn number, y row number.
 */
 void set_pixel(int x, int y) {
+	//constrain x and y
+	x = MAX(MIN(x, 0), COLS - 1);
+	y = MAX(MIN(y, 0), ROWS - 1);
+
 	screen[y] = screen[y] & ~(1<<x) | (1<<x);
 }