diff --git a/src/controls/PixelPainterControls.js b/src/controls/PixelPainterControls.js index 8dcdbad..807f1bc 100644 --- a/src/controls/PixelPainterControls.js +++ b/src/controls/PixelPainterControls.js @@ -182,17 +182,23 @@ class PixelPlainterControls { if (scale < 3) return; const curColor = renderer.getColorIndexOfPixel(...cell); - if (selectedColor !== curColor) { - const { canvasSize } = state.canvas; - const [i, j] = getChunkOfPixel(canvasSize, ...cell); - const offset = getOffsetOfPixel(canvasSize, ...cell); - tryPlacePixel( - store, - i, j, offset, - selectedColor, - curColor, - ); + if (selectedColor === curColor) { + return; } + const { canvasSize } = state.canvas; + const [x, y] = cell; + const maxCoords = canvasSize / 2; + if (x < -maxCoords || x >= maxCoords || y < -maxCoords || y >= maxCoords) { + return; + } + const [i, j] = getChunkOfPixel(canvasSize, x, y); + const offset = getOffsetOfPixel(canvasSize, x, y); + tryPlacePixel( + store, + i, j, offset, + selectedColor, + curColor, + ); } static getMultiTouchDistance(event: TouchEvent) { @@ -377,7 +383,21 @@ class PixelPlainterControls { this.viewport, [clientX, clientY], ); - if (!hover || hover[0] !== screenCoor[0] || hover[1] !== screenCoor[1]) { + const [x, y] = screenCoor; + + /* out of bounds check */ + const { canvasSize } = state.canvas; + const maxCoords = canvasSize / 2; + if (x < -maxCoords || x >= maxCoords + || y < -maxCoords || y >= maxCoords + ) { + if (hover) { + store.dispatch(unsetHover(screenCoor)); + } + return; + } + + if (!hover || hover[0] !== x || hover[1] !== y) { store.dispatch(setHover(screenCoor)); } if (this.holdPainting && !this.coolDownDelta) { diff --git a/src/core/draw.js b/src/core/draw.js index 4059128..01026a2 100644 --- a/src/core/draw.js +++ b/src/core/draw.js @@ -66,10 +66,12 @@ export async function drawByOffsets( */ if (i >= canvasSize / tileSize) { // x out of bounds + // (we don't have to check for <0 becaue it is received as uint) throw new Error(2); } if (j >= canvasSize / tileSize) { // y out of bounds + // (we don't have to check for <0 becaue it is received as uint) throw new Error(3); } if (canvas.req !== -1) {