Skip to content

Crash when setting width/height on canvas: core dumped #2520

Closed

Description

@948764321

Title: Intermittent bug in canvas. width assignment after specific operations (v3.1.1)

Description:
After updating to node-canvas v3.1.1, my application started failing intermittently when assigning values to canvas.width.

Key observations:

The failure occurs only in my existing application code

Cannot reproduce with a minimal standalone demo containing only canvas. width assignments

The critical difference:

In my application, additional operations precede the canvas. width assignment

These pre-assignment operations appear to trigger the failure

Evidence:
The same error occurs in

import { createCanvas } from 'canvas';
import fs from 'node:fs';

const canvas = createCanvas(1, 1, 'pdf');
const context = canvas.getContext('2d');

context.canvas.width = 595.3; // <------- crashes
context.canvas.width = 595.3; // <------- crashes
context.canvas.width = 595.3; // <------- crashes
context.canvas.width = 595.3; // <------- crashes
context.canvas.height = 595.3; // <------- crashes

context.fillStyle = 'green';
context.fillRect(10, 10, 150, 100);

const pngStream = canvas.createPDFStream();
const out = fs.createWriteStream('./output.pdf');
pngStream.pipe(out);

out.once('finish', () => {
  console.log('✓ saved as output.pdf');
});

suggesting this is a regression in v3.1.1 related to canvas state management when modifying properties after certain operations.

Activity

  1. chearon commented on Jun 25, 2025

    @chearon
    Collaborator

    Thanks. I can reproduce the problem and I think I know what caused it. I'll have a fix soon.

  2. added a commit that references this issue on Jun 30, 2025
    2738a70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions