From 9977673941b5090ae6a4db8c6364b5d02230f8fc Mon Sep 17 00:00:00 2001 From: Lauren McCarthy Date: Thu, 16 May 2019 22:12:46 -0700 Subject: [PATCH] fixing mouseX, mouseY and touchX, touchY for noCanvas and createCanvas(0, 0) cases closes #3749 --- src/events/mouse.js | 4 ++-- src/events/touch.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/events/mouse.js b/src/events/mouse.js index 72713d7d93..f6a17cb20f 100644 --- a/src/events/mouse.js +++ b/src/events/mouse.js @@ -404,8 +404,8 @@ function getMousePos(canvas, w, h, evt) { } } var rect = canvas.getBoundingClientRect(); - var sx = canvas.scrollWidth / w; - var sy = canvas.scrollHeight / h; + var sx = canvas.scrollWidth / w || 1; + var sy = canvas.scrollHeight / h || 1; return { x: (evt.clientX - rect.left) / sx, y: (evt.clientY - rect.top) / sy, diff --git a/src/events/touch.js b/src/events/touch.js index aa6e76328f..7a64dacdf4 100644 --- a/src/events/touch.js +++ b/src/events/touch.js @@ -59,8 +59,8 @@ p5.prototype._updateTouchCoords = function(e) { function getTouchInfo(canvas, w, h, e, i) { i = i || 0; var rect = canvas.getBoundingClientRect(); - var sx = canvas.scrollWidth / w; - var sy = canvas.scrollHeight / h; + var sx = canvas.scrollWidth / w || 1; + var sy = canvas.scrollHeight / h || 1; var touch = e.touches[i] || e.changedTouches[i]; return { x: (touch.clientX - rect.left) / sx,