Pārlūkot izejas kodu

fixed out of bounds error

subDesTagesMitExtraKaese 3 gadi atpakaļ
vecāks
revīzija
8520452729
1 mainītis faili ar 4 papildinājumiem un 0 dzēšanām
  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);
 }