You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Node 24 crash when setting width/height on canvas: Check failed: static_cast<int64_t>(amount_before) >= -delta. #2514
import{createCanvas}from'canvas';importfsfrom'node:fs';constcanvas=createCanvas(500,500);constcontext=canvas.getContext('2d');canvas.width=1000;// <------- crashescontext.fillStyle='green';context.fillRect(10,10,150,100);constpngStream=canvas.createPNGStream();constout=fs.createWriteStream('./output.png');pngStream.pipe(out);out.once('finish',()=>{console.log('✓ saved as output.png');});
When setting the width/height of the canvas-element (version 3.1.0) after creating it, node 24 crashes. When running the code above with node 23.11.0, everything works as expected. When using 24.0.1, it crashes with the following stack trace:
When setting the width/height of the canvas-element (version 3.1.0) after creating it, node 24 crashes. When running the code above with node 23.11.0, everything works as expected. When using 24.0.1, it crashes with the following stack trace:
I had upgraded a small server to Node.js 24.0.0 and started seeing Segment Fault crashes from various modules. I didn't have time to install the segfault-handler package and investigate further so downgraded to 22.15.0 and everything was normal again. I figured 24.0.0 doesn't go LTS until October so there is time to work on it,
When the canvas is re-allocated, we're reporting the new size as the freed memory size instead the old size. Apparently Node 24 is stricter about such errors, and crashes. I'm adding node 24 to CI, but for some reason, our tests don't trigger the crash (even though we have code similar to the snippet in the OP). I was able to trigger it locally though.
Upgraded to Canvas 3.1.1 as well as Node.js 24.2.0. With no changes to any of my code I am no longer seeing the Segmentation Fault's that were happening with 3.1.0 and Node.js 24.0.0 (which was the initial release I had upgraded to before dropping back to 22.x.x). This appears to have fixed the issue.
Activity
Whobeu commentedon May 13, 2025
I had upgraded a small server to Node.js 24.0.0 and started seeing Segment Fault crashes from various modules. I didn't have time to install the segfault-handler package and investigate further so downgraded to 22.15.0 and everything was normal again. I figured 24.0.0 doesn't go LTS until October so there is time to work on it,
[-]Node 24 crash: Check failed: static_cast<int64_t>(amount_before) >= -delta.[/-][+]Node 24 crash when setting width/height on canvas: Check failed: static_cast<int64_t>(amount_before) >= -delta.[/+]chearon commentedon Jun 16, 2025
When the canvas is re-allocated, we're reporting the new size as the freed memory size instead the old size. Apparently Node 24 is stricter about such errors, and crashes. I'm adding node 24 to CI, but for some reason, our tests don't trigger the crash (even though we have code similar to the snippet in the OP). I was able to trigger it locally though.
report correct freed size when resurfacing
Whobeu commentedon Jun 20, 2025
Upgraded to Canvas 3.1.1 as well as Node.js 24.2.0. With no changes to any of my code I am no longer seeing the Segmentation Fault's that were happening with 3.1.0 and Node.js 24.0.0 (which was the initial release I had upgraded to before dropping back to 22.x.x). This appears to have fixed the issue.