Merge pull request #968 from paulkaplan/fix-eyedropper-crash

Fix Safari crash in color picker
This commit is contained in:
DD Liu 2020-02-04 18:49:24 -05:00 committed by GitHub
commit 56e0332ed2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -41,7 +41,16 @@ class LoupeComponent extends React.Component {
const imageData = tmpCtx.createImageData(
loupeDiameter, loupeDiameter
);
// Since the color info comes from elsewhere there is no guarantee
// about the size. Make sure it matches to prevent data.set from throwing.
// See issue #966 for example of how that can happen.
if (this.props.colorInfo.data.length === imageData.data.length) {
imageData.data.set(this.props.colorInfo.data);
} else {
console.warn('Image data size mismatch drawing loupe'); // eslint-disable-line no-console
}
tmpCtx.putImageData(imageData, 0, 0);
// Scale the loupe canvas and draw the zoomed image

View file

@ -99,8 +99,8 @@ class EyeDropperTool extends paper.Tool {
y: y,
color: colors.data,
data: bufferContext.getImageData(
(artX * ZOOM_SCALE) - (LOUPE_RADIUS * ZOOM_SCALE),
(artY * ZOOM_SCALE) - (LOUPE_RADIUS * ZOOM_SCALE),
ZOOM_SCALE * (artX - LOUPE_RADIUS),
ZOOM_SCALE * (artY - LOUPE_RADIUS),
LOUPE_RADIUS * 2 * ZOOM_SCALE,
LOUPE_RADIUS * 2 * ZOOM_SCALE
).data,