瀏覽代碼

fixed out of bounds error

subDesTagesMitExtraKaese 3 年之前
父節點
當前提交
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);
 }