소스 검색

fixed out of bounds error

subDesTagesMitExtraKaese 4 년 전
부모
커밋
8520452729
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  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);
 }