samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.7k stars 66 forks source link

[Silent Crash] Turning canvas into buffer repeatedly causes silent crash #49

Closed ewanhowell5195 closed 2 years ago

ewanhowell5195 commented 2 years ago

If you repeatedly turn the same canvas into a buffer, it gets slower and slower until it crashes with no error message.

This example code below demonstrates this, and crashes after around 2520 iterations.

import {Canvas} from "skia-canvas"

const canvas = new Canvas(1, 1)
const ctx = canvas.getContext('2d')
let i = 1
while(true){
    console.time(i)
    await canvas.png
    console.timeEnd(i++)
}

.png, .jpg, .toBuffer() and .toDataURL() all cause this crash.

The size of the canvas doesn't seem to make a difference to how long it takes to crash.

Please note, creating a new canvas every iteration does not cause this issue. It is only using the same canvas that causes it.