Bug in Playground

Hello everyone!

I was told to use playgrounds when I started to learn BJS (in JavaScript), but I wasn’t comfortable cause of one bug (not so major, but irritating). Seeing this forum asking people to use playgrounds more, I thought let me mention the bug.

DISCLAIMER: I ain’t any expert, just a beginner :smiley:. Please point out if I am wrong.

So I was figuring out the necessity of using the “new” keyword for creating things cause I had noticed that the “new” keyword isn’t required when creating meshes. During that, I removed the “new” keyword from BABYLON.Scene(engine); , it said an error. Yeah so as a rule of thumb, I undone my code and expected it to return back. But nope, it just mentions another error. I was already a bit frustrated and this made me really angry. Now whatever I try to do the error just doesn’t go!

You can check it out for yourself in the demo playground which comes up when u open a playground. (I’m so pissed off due to this, that’s why I didn’t mention any link or errors).

Please tell me where am I wrong if I am. And if I’m not, I would hope to see a fix anytime soon!

Thanks for reading through!

No error for me when opening https://playground.babylonjs.com/, being in Typescript or Javascript.

I’m afraid you will have to give more details / screenshots.

1 Like

I am not an expert either so I may also be wrong in this explanation. The code ( P ) in the playground is executed by an overarching code (A) which retains some information about P so that pressing the play button runs P without re-loading A. Now the error you created by deleting new created a stored error in A so that re-running the code executed this stored error. Now whether this is a bug or a necessity of the way the playground works I do not know but @Deltakosh will.

Now to answer some of your comments

Using the browser refresh button will clear this problem.

You need the new keyword when the function you are calling is a constructor function. That is when you are creating an new instance of a class. Calling Scene you are calling a constructor function.

There are also static functions, these are in a sense helper functions where you pass some parameters and the static function uses a constructor function to create a new instance and uses the passed parameters to set specific properties for the instance. For example MeshBuilder.CreateBox is a static function that calls the constructor for a Mesh and having created an instance of a new Mesh uses the parameters to set the vertex positions, normals, indices and uvs of a box mesh.

Hope that helps.

It is a good thing to learn by experimenting and seeing what works and what doesn’t. What you have to be prepared for is that breaking fundamental structures might produce errors that designers never expected to happen and you cannot get out off. In which case you have to switch off and on again, ie refresh the browser.

Good learning and keep experimenting and asking when unsure :slightly_smiling_face:

1 Like

The error occurs if you delete the new keyword in front of Scene press Run and then put the new keyword back in front of Scene and press Run again (A strange thing to do but a legitimate experiment - when coding always expect the unexpected)

Thanks for the explanation, I did not understand the use case.

Well, it’s a small change I think @Deltakosh will be able to do:

In Playground/js/main.js, line 45 there is:

if (BABYLON.Engine.LastCreatedScene && BABYLON.Engine.LastCreatedScene.debugLayer.isVisible()) {

by changing it to:

if (BABYLON.Engine.LastCreatedScene && BABYLON.Engine.LastCreatedScene.debugLayer && BABYLON.Engine.LastCreatedScene.debugLayer.isVisible()) {

it corrects the problem.


Yes, reloading the page works, but losing the code is the problem. I get it you can copy all the code and then paste it back, but it I am not very comfortable with doing that.

Anyways, Thanks a lot @JohnK! If you evaluate yourself as a beginner, IDK what am I :laughing:, maybe an absolute noob?

WIll fix that :slight_smile: Thanks @Evgeni_Popov