Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.16k stars 1.17k forks source link

repeat call on loadImage does not clear the previous image #1758

Open shen-lin opened 3 years ago

shen-lin commented 3 years ago

Issue or Feature

The code below can be triggered repeatedly. E.g. by click a button. Everything a dynamically generated image is returned by the backend. I already clear the context before drawing the image. But the image is still repeated drawing over the previous images. The only thing I can think about is the loadImage is returning image that draws over previous image.

Steps to Reproduce

var {loadImage, createCanvas} = require('canvas');
const image = await loadImage(`/newimage?${Math.random()}`);
const canvas = createCanvas(200, 200);
const context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(0, 0, 0, 1)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.drawImage(terrain, 0, 0, canvas.width, canvas.height);

Your Environment

Version: "2.6.1" Environment: Chrome browser

zbjornson commented 2 years ago

That code looks correct and I can't reproduce the issue. Are you still encountering this? Are you actually running in Chrome?