Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Commit

Permalink
Capped this.data size in imageData creation (#86)
Browse files Browse the repository at this point in the history
Fixes #85.
  • Loading branch information
Josh Goldberg authored Oct 2, 2019
1 parent ab0b86d commit e1a95f9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/SpriteSingle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export class SpriteSingle {
* @returns A canvas with the rendered sprite.
*/
private createCanvas(width: number, height: number): HTMLCanvasElement {
const canvas: HTMLCanvasElement = document.createElement("canvas");
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;

const context: CanvasRenderingContext2D = canvas.getContext("2d")!;
const imageData: ImageData = context.getImageData(0, 0, width, height);
const context = canvas.getContext("2d")!;
const imageData = context.getImageData(0, 0, width, height);

imageData.data.set(this.data);
imageData.data.set(this.data.slice(0, Math.min(imageData.data.length, this.data.length)));
context.putImageData(imageData, 0, 0);

return canvas;
Expand Down

0 comments on commit e1a95f9

Please sign in to comment.