I'm working on a drawing page where I have multiple buttons. My problem is with the undo button. When I draw 3 lines on the canvas, and then click on undo, everything works great. But when I'm trying to draw again, the undooed lines are appearing again.
Can anyone please help me with this?
This is my undo function:
function cUndo() {
if (cStep > 0) {
cStep--;
var canvasPic = new Image();
canvasPic.setAttribute('crossOrigin', 'anonymous');
canvasPic.src = cPushArray[cStep];
context.clearRect(0, 0, 575, 575);
canvasPic.onload = function() {
context.drawImage(canvasPic, 0, 0, 575, 575);
}
}
}
And this is the entire app:
