mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 21:42:30 -05:00
Merge pull request #968 from paulkaplan/fix-eyedropper-crash
Fix Safari crash in color picker
This commit is contained in:
commit
56e0332ed2
2 changed files with 12 additions and 3 deletions
|
@ -41,7 +41,16 @@ class LoupeComponent extends React.Component {
|
|||
const imageData = tmpCtx.createImageData(
|
||||
loupeDiameter, loupeDiameter
|
||||
);
|
||||
imageData.data.set(this.props.colorInfo.data);
|
||||
|
||||
// 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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue