New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node: cairo-pattern.c:1127: cairo_pattern_destroy: Assertion failed. none - catched error #1357
Comments
This sounds like a bug in cairo. Can you post an example PDF that causes this consistently, and ideally the full code to run it (e.g. I'm not sure what |
i have the same bug, reproductible with fabricJS and i m working to replicate it in plain JS code. Assertion failed: (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&pattern->ref_count)), function cairo_pattern_destroy, file cairo-pattern.c, line 1127. The bug arised moving fabricJS tests and library from canvas 1.x to canvas 2 ( actually the bug is stopping the migration ) this happens during test UTs. |
As an additional reference, the error does not happen running the test file alone, it happens only running a multitude of tests one after another, |
As I wrote, I can't attach the PDF because it's sensitive file. Sorry.
|
i mean, can you reproduce without the sensitive information? On my side i found how to avoid the error, but not how to reproduce it outside the lot of code i have. trying |
Hi, i have the same issue here using node canvas and pdfjs. This is a file to reproduce : This is my sample code: const Canvas = require('canvas');
const assert = require('assert');
const fs = require('fs');
const util = require('util');
const jsdom = require('jsdom');
const pdfjsLib = require('pdfjs-dist');
const writeFile = util.promisify(fs.writeFile);
const dom = new jsdom.JSDOM(`...`);
global['document'] = dom.window.document;
class NodeCanvasFactory {
create(width, height) {
assert(width > 0 && height > 0, 'Invalid canvas size');
const canvas = Canvas.createCanvas(width, height);
const context = canvas.getContext('2d');
return {
canvas: canvas,
context: context,
};
}
reset(canvasAndContext, width, height) {
assert(canvasAndContext.canvas, 'Canvas is not specified');
assert(width > 0 && height > 0, 'Invalid canvas size');
canvasAndContext.canvas.width = width;
canvasAndContext.canvas.height = height;
}
destroy(canvasAndContext) {
assert(canvasAndContext.canvas, 'Canvas is not specified');
// Zeroing the width and height cause Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption.
canvasAndContext.canvas.width = 0;
canvasAndContext.canvas.height = 0;
canvasAndContext.canvas = null;
canvasAndContext.context = null;
}
};
async function main (){
// Relative path of the PDF file.
const pdfURL = './test.pdf';
// Read the PDF file into a typed array so PDF.js can load it.
const rawData = new Uint8Array(fs.readFileSync(pdfURL));
// Load the PDF file.
pdfDocument = await pdfjsLib.getDocument(rawData).promise;
for (let i = 1; i <= pdfDocument.numPages; i++) {
console.log('page', i);
// Get page
const page = await pdfDocument.getPage(i);
// Render the page on a Node canvas with 100% scale.
const viewport = page.getViewport(1.0);
const canvasFactory = new NodeCanvasFactory();
const canvasAndContext = canvasFactory.create(viewport.width, viewport.height);
const renderContext = {
canvasContext: canvasAndContext.context,
viewport: viewport,
canvasFactory: canvasFactory,
};
await page.render(renderContext).promise;
const image = canvasAndContext.canvas.toBuffer();
await writeFile(`page_${i}.png`, image);
}
}
main(); Here is my results:
run 1:
run 2:
It seems not related to page 28 particulary, starting to page 27 works fine to the end. starting to page 25 fails on page 26:
Hope this helps :) |
@asturur can you describe the workaround you're using to avoid the error? I'm having the same issue using Fabricjs and running unit tests. My "workaround" is disposing the fabric canvas after each test. |
@zbjornson still facing this issue in latest version of canvas |
@sheikalthaf can you post repro info please? |
@zbjornson same issue Please find a project to reproduce: Thanks for your help ! |
Thanks @lvauvillier , I'll try to take a look later this week. |
@zbjornson tell me if you need help or more test pdfs |
im hitting this too, although not using pdfs |
I've found it doesn't happen if in my tests I add a delay before each
update - it seems to still happen sometimes :( |
any solution/workaround for this problem? |
@zbjornson can we reopen this bug? |
Sorry for the delay, hoping to work on this this week. |
The crash @lvauvillier posted is fixed by 7baaecf, so we just need to make a release. (Or folks can build from source, https://github.com/Automattic/node-canvas#compiling.) @LinusU ? :) Sorry for the delay realizing that was the only issue! |
Cut a new release as 2.6.1 🚀 install it with |
Hi @zbjornson @LinusU , thanks a lot for your fix But i cannot install it... Here is my npm log file :
|
failing for me too |
|
Note that we don't have pre-builds for 2.6.1 yet, so you have to install the prerequisites for building in order for it to work: brew install pkg-config cairo pango libpng jpeg giflib librsvg When pre-builds are available we will promote it from |
Thanks. |
I already moved from this project, but still, thank you for the good work! |
Hi @LinusU! Any idea on when this is going to be released? I'm experiencing this exact issue |
Hmm, @chearon it seems like the 1.6.1 tag is created but is without assets, do you know what the status is on that one? ❤️ |
Oops, I'm running the builds now |
Thanks! |
Hey guys, are those builds available somewhere? |
@chearon sorry to bother, are those builds available somewhere? |
Seems to be working fine and fixes the issue I was having, thanks a lot! |
Promoted |
Thanks! |
Issue or Feature
When using canvas to render image from pdf by pdf.js on server side.
With some pdf files (but not all of them) I got this error:
node: cairo-pattern.c:1127: cairo_pattern_destroy: Assertion `(_cairo_atomic_int_get (&(&pattern->ref_count)->ref_count) > 0)' failed. Program node index.js exited with code null
no way to catch the error and proceed my script.
I paste here my code even the real rendering (I assume) is deep into pdf.js code.
The file itself is also private, so I can't attach it.
what I expect to have
At least catchable error. Not to have it all would be better, of course.
Steps to Reproduce
Your Environment
The text was updated successfully, but these errors were encountered: