It’s been a long time since I last posted on this forum. Thank you all again for both this amazing library and community !
I’m running into an issue with EngineStore.LastCreatedEngine in the context of creating a simple GUI Element (directly copied from this playground
Even though the involved code is simple, the project structure is not:
I have 2 different projects, the first one (let’s call it ‘mainApp’) is importing the second one (call it ‘core’) as an npm package (through npm link if it helps). I am the maintainer of both projects.
Basically what happens is:
- mainApp imports core as an npm package
- mainApp imports and uses two classes from core:
- one that performs the general setup of a baseScene (equivalent of the Playground, call it ‘SceneManager’ with a CreateScene method)
- the other one that is abstract (‘SceneLayoutBuilder’) and extended in the mainApp project (as ‘MySceneLayoutBuilder’) and called by the CreateScene method through the ‘SceneLayoutBuilder’ type.
Here is a playground. in this context it is working but it is better to illustrate the structure of my code (that I cannot share unfortunately). The facts that it is working in Playground makes me think that it could be related to the way the packages are imported but I couldn’t go further on my own.
Although this complicated setup works fine when I am creating simple objects as spheres, planes etc… it is not working when I try to add some GUI elements.
Actually only those three lines are sufficient to make the error appear.
const advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI("myUI", true, scene); var button1 = Button.CreateSimpleButton("but1", "Click Me"); advancedTexture.addControl(button1);
Here is the error I get :
babylon.gui.js:6730 Uncaught Error: Invalid engine. Unable to create a canvas. at Control._GetFontOffset (babylon.gui.js:6730:1) at TextBlock._processMeasures (babylon.gui.js:15921:1) at Control._layout (babylon.gui.js:6091:1) at Container._layout (babylon.gui.js:4245:1) at Container._layout (babylon.gui.js:4245:1) at AdvancedDynamicTexture._render (babylon.gui.js:1244:1) at AdvancedDynamicTexture._checkUpdate (babylon.gui.js:1219:1) at AdvancedDynamicTexture._render (babylon.gui.js:1237:1) at AdvancedDynamicTexture._checkUpdate (babylon.gui.js:1219:1) at c.callback (babylon.gui.js:620:94)
When looking into the line where the error is thrown, it seems that EngineStore.LastCreatedEngine becomes empty at some point in the code. I seems to happen just before the call to the ‘initScene’ method (through the abstract class).
I’ve looked into this forum post, talking about the same error, and tried several suggestions such as checking that the versions of babylonjs packages were the same in both projects but it seems to be the case (5.42.1 which must be the latest version at this time). I also tried to downgrade to an arbitrary version (5.20.0) but the error is still the same.
I hope this is understandable and I would appreciate any help that could preserve some of my nerves!
Thank you for your time !