I am using node-canvas for drawing an image, this error occurs when the code is ran:
Assertion failed: (tmp.table_size - hash_table_sizes < ARRAY_LENGTH (hash_table_sizes)), function _cairo_hash_table_manage, file cairo-hash.c, line 286.
/var/folders/ll/02j8nvys66176tszvw01w1c00000gq/T/start6586898863.sh: line 2: 17744 Abort trap: 6 ts-node src/index.ts
Please notice that I use TypeScript, and this fact may be the reason of the error. I also found this issue opened & fixed on GitHub. As it was marked as fixed and worked for other users, I can think that TypeScript code compiling causes this error.
Code:
const canvas = Canvas.createCanvas(1772, 633);
const ctx = canvas.getContext('2d');
// Register fonts
Canvas.registerFont(join(__dirname, `../Fonts/Panton-BlackCaps.otf`), {
family: 'Panton-BlackCaps',
});
Canvas.registerFont(join(__dirname, `../Fonts/coolvetica rg.otf`), {
family: 'Coolvetica',
});
// Get the background image and draw it
const background = await Canvas.loadImage(
join(__dirname, `../Images/background.png`)
);
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
// Get info about the user
const username = `${member.user.username}#${member.user.discriminator}`;
const avatar = await Canvas.loadImage(
member.user.displayAvatarURL({ format: 'jpg' })
);
// Draw the avatar
ctx.beginPath();
ctx.arc(322, 280, 208, 0, Math.PI * 2, true); // Position of the avatar
ctx.closePath();
ctx.shadowColor = '#000000';
ctx.shadowBlur = 16;
ctx.clip();
ctx.drawImage(avatar, 322, 280, 500, 500);
// Checks username length and draws text depending on it
if (username.length >= 14) {
ctx.font = '70 px Coolvetica';
ctx.fillStyle = '#ffffff';
ctx.shadowColor = '#000000';
ctx.shadowBlur = 7;
ctx.fillText(username, 322.42, 546.79);
} else {
ctx.font = '93 px Coolvetica';
ctx.fillStyle = '#ffffff';
ctx.shadowColor = '#000000';
ctx.shadowBlur = 7;
ctx.fillText(username, 322.42, 546.79);
}
// Draws the WELCOME! text
ctx.font = '195.35 px Panton-BlackCaps';
ctx.fillStyle = '#ffffff';
ctx.shadowColor = '#000000';
ctx.shadowBlur = 7;
ctx.fillText('WELCOME!', 1177, 287.55);
// Draws the Enjoy your stay! text
ctx.font = '99.71 px Coolvetica';
ctx.fillStyle = '#ffffff';
ctx.shadowColor = '#000000';
ctx.shadowBlur = 7;
ctx.fillText('Enjoy your stay!', 1177, 398.46);
It appears that npm rebuild
fully resolves this issue.
Deleting node_modules
folder and running npm install
will also work as an alternative method.