Scene render misbehavior on first change

I am running into a weird issue in with the initial load and first time point change.

PG

The first model doesn’t display until you either resize the engine or rotate the view (I am missing a scene.render call somewhere, but can’t seem to figure out where to put it.)

Also on the first timepoint change (pressing z, x, or moving the slider) the model disappears for one frame, but then it works perfectly afterwards.

Hoping some fresh eyes will help sort this out :slight_smile:

1 Like

Without going super deep on understanding your code flow, this isn’t an answer, but it might be an interesting clue.

Final - Render on Demand: Single Asset per frame | Babylon.js Playground (babylonjs.com)

All I did here was to move the code that sets the slider value at the start to after the onValueChanged handler is set so that that handler gets hit by the initial value set, not just later ones. Interestingly, the result of this (upon pressing “Play,” nondeterministic for me on load) is that the model momentarily appears as expected, then disappears almost immediately after. This makes me think that there’s something the logic flow that’s not just failing to render the model, it’s telling the code to not render the model even if it already has.

Best guess at the moment is that the asynchrony you’re going for here has gotten out of order, and something is happening at a time when it’s not supposed to. As crude as this mechanism is, I’d recommend good old fashioned “printf debugging” for this: litter your code with checkpoint lines such as console.log("Checkpoint 1"), then make sure they’re all happening in the order you expect them to. If there are out-of-order operations happening, this is probably the simplest way I know to track them down. Hope this helps, and best of luck!

2 Likes

Just set cameraChanged = true; before setting your own render loop to fix the problem at loading time.

Regarding the other problem, it’s probably because one of the shader was not compiled yet when scene.render is called so nothing can’t be displayed. You should wait for everything to be ready before rendering the scene. You can do it by using scene.executeWhenReady:

https://playground.babylonjs.com/#C4AT7T#13

Correction: you also have the same problem with shaders not being ready for the first frame, so you should use the same solution, meaning using scene.executeWhenReady (see PG).

3 Likes

Thank you @Evgeni_Popov and @syntheticmagus!

I made a few tweaks off of your suggestions and it works the way I am happy with now. The remaining hairs on my head thank you!

https://playground.babylonjs.com/#C4AT7T#15