So this is a strange one and I understand that this is not really a common use case.
For my Figma to BabylonJS Figma plug-in. I have decided to rewrite it to use actual BabylonJS controls from NPM rather than just using my own custom-made psedo-controls. This is worked very well for things like containers, lines, rectangle etc… however when I am on font I have noticed that my plug-in is crashing, showing the error message if I try to give it a new font size, style or weight.
Invalid engine. Unable to create a canvas.
Again, other controls will Serialize fine, however, when I try to serialise a text block that I have tried to change its font size or its weight or its style. I get that error.
The error message suggests that Babylon.js is trying to create a canvas to measure the text metrics (fontWeight/Stlye/Size, in this case). I think this is likely happening during the serialization process, as i assume Babylon.js needs to calculate these metrics to accurately serialize the TextBlock control?
My question is, is there a way that I could simply skip this?
I think it’s quite strange behaviour since this isn’t required for other elements. I understand that a lot of the text stuff reflects real world CSS. Just wanted to ask if it’s possible that I skip the creating a fake canvas.
I got the latest version with this new change, but it only works for controls. I try to add the AllowCanvas to Containers it wont work as containers dont have it.
I add all the controls to a container then run the seralize once on a container. Not sure how to achive this with just controls as controls cant have children added to them. Is there some Typescipt namespace issue I am not seeing?
Hello @Deltakosh , sorry i feel like the most annoying person right now…
The allowCanvas = false works in that I don’t get an error on canvas-less environments. However, anything to do with font size, fontweight, and fontfamily is completely omitted from the serialization output. I need a playground here (you need to use the console to see the output) https://playground.babylonjs.com/#XJC2MY#1
The expected output is that whenever I set the font, size too, should still be in the serialzed output, even if it skips the canvas.
Sorry been a long time since I updated this. I found the issue but can’t recreate it on the playground because it always has a canvas even if give allowCanvas=false during serialization. Same goes for my dev env.
I don’t mind making a PR but I can’t get this error to fire with normal testing because there is always a canvas.
This error occurs when I run my Figma to Babylonjs plugin.
This isn’t an issue on normal TextBlocks, only happens on Buttons but I assume could happen in Grids too since they also have an override during serialization.