LinesMesh does not render

Hello,
I am currently debugging a number of issues in my application related to objects sometimes not showing up. I have an application architecture without a render loop: I manually call scene.render whenever my data model changes. I also found out that sometimes the scene is not yet ready to render, so I await scene?.whenReadyAsync() before calling scene.render. This solved some problems where I missed rendering some objects and they where only shown after the next time a render was triggered. Now I have one more issue left that I cannot reproduce in the playground but it is happening in my application still and it looks suspiciously close:

  • I have two LineMeshes that are created with CreateLineMesh. I am using thin instances to draw many instances of these line meshes.
  • After setting the matrix buffer and enabling the meshes with setEnabled and re-render the scene, they are not shown. Calling this process one or two times in a row results in the line meshes finaly beeing shown.
  • I noticed that LineMesh also has a property isReady, however, in my case, this always returns true.
  • I see however, that the version of isReady of the regular Mesh accepts two booleans. I can cast the LineMesh to a regular mesh pass the two booleans, however, isReady is still true even directly after creating the mesh.

I am using the pattern of creating a single mesh and then use thin instances to draw many items on the screen all over in my application. However, it seems like there is something special for LineMeshes that they initiate some kind of asyncronous initialization and I do not know how to wait for it to finish.

Any ideas?
Best regards,
Axel

that should work :slight_smile:
Can you repro in the playground so we can debug?

@deltakosh I was playing more with the PGs I sent you on video and I started to experience more psychopatic behavior :smiley: of the PGs. It was similar as @axeljaeger is describing it. The higlight from the sphere got lost from the good PG which was previosly showing it. I had to refresh a couple of times to get it again working. After a while (I was trying the second PG) I run again the code in the good PG and it was failing again - no highlight. I added one more scene.render() call (so there were two of them), ran the PG and it worked :smiley:

Isn’t there a global object which gets modified by both PGs?

impossible! Tabs are isolated else we have A MAJOR security issue in the browser

2 Likes

I’m going to try out other browsers with the same PGs.

EDIT:
@Deltakosh

Results on MAC:
Chrome - unpredictable
Firefox - always working, whatever I was doing, multiple refreshes, RUN, RUN, refresh, RUN, etc…
Safari - on load - didn’t work. On refresh it started to work and is behaving like Firefox

Now that’s something :smiley:

This is crazy! can you share the PG?

Yep

@sebavan

Just tell me I wasn’t right when I wrote this:

@Tricotou @mawa @CrashMaster

2 Likes

Ok here is my analysis:
Depending on how fast or slow the browser is we may endup rendering the scene too early.

In chrome this is mostly because we rely on parallel shader compilation:
Babylon.js Playground (babylonjs.com)

If you turn it off, it will work. This is why @roland you have some tabs that work: because the shader compilation is cached at browser level

2 Likes

So we ended up having something global for both PGs :slight_smile: the shader cache…

However if that’s the case, why was one of the PGs working and the second one in the same browser not working. Shouldn’t the second one use the precached shader?

In this PG I kill the render loop onSceneReady yet still not working.

we don’t really know how the cache works. Maybe the first one invalidates something?

The thing is that this is related to the shaders being async.

Killing the renderloop is not the problem here (well it is of course but if you have no renderloop then you must call scene.render() at the right time)

So we can say basically that on demand rendering is safe when we:

  1. disable paralell shader compilation: engine.getCaps().parallelShaderCompile = null
  2. kill the render when the scene is ready: scene.onSceneReadyObservable.addOnce(() => engine.stopRenderLoop())
  3. we have to call scene.render() when we want to render the changes to the scene

This PG renders the changes one by one:

This PG renders the changes all at once:

Observables will not work because they needs the render loop to be running. So in case we change the camera we need to set forceRender = true as well and we can’t use the camera.onViewMatrixChangedObservable

2 Likes

Hey,
thanks for all the contributions so far. I tested the main conclusion here so far in my application:

engine.getCaps().parallelShaderCompile = null;

and it changes indeed the behavior into the right direction:
So far I have two line meshes and both of them are toggled using a checkbox-style ui element.
Old behavior:

  • First toggle: Nothing happens.
  • Second toggle: One of them appears, always the same one.
  • Third toggle: Both are now visible.

After disabling parallel shader compilation, the one mesh already appears after the first click, while the second one appears after the second click. So it is definitely a step in the right direction, now I have to find out why both meshes behave in a different way and why the second one needs another click.

Thank you all so far!

We need to see a PG.

Hi Roland,
after further digging into it, I was able to solve it!
I had some code that basically re-created my thin-instance buffers many times during the preparation of the line meshes. I compared what was different between the two line meshes and saw that the initialization sequence was different.

Thank you all again!

2 Likes

Huh? I believe I get it but… for the sake of our understanding and definetely closing this topic… Would it be too much to ask you to post the ‘working’ PG? I believe it would benefit everyone here. Thanks and have a great day :sunglasses:

1 Like

What is ‘Volvo’? Are these guys really still making cars? :oncoming_automobile: :joy: :rofl:

1 Like

This counts (the end game) as one of my worst experiences helping someone out :smiley: :smiley: :smiley:

@axeljaeger Take this easy! :smiley: I’m not upset, just trying to be funny!

However be more specific next time, please! You didn’t even mention a word about thin instances…

Honestly, I can’t comment this part. I’m not entitled to. The number of times I posted a potential bug or unexpected behavior because I had just no faen clue of what was going on in my script/project is countless :sweat_smile: :face_with_hand_over_mouth: Now, I don’t just check once or twice before posting… Rather multiple times and yet, I’m still not sure of whether (for once) I got it right :sweat_smile: :rofl:

1 Like