RenderTargetTexture error

This code in the RenderTargetTexture function sometimes fails on me:
for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
var subMesh = mesh.subMeshes[subIndex];
this._renderingManager.dispatch(subMesh, mesh);
}

It crashes when there are no subMeshes for that mesh. I put a temp fix in to check if the mesh has subMeshes before executing this for loop. Its a hack though. There might be a deeper issue somewhere else

You should not add meshes to the RTT.renderList if they do not have subMeshes

I will add the check in the code anyhow :slight_smile:

Well there is already a check actually:

Which version are you on?

I’m using the latest version. I also tried the preview version.
Yes, the code is the same as above, however if gets past that initial IF statement but when it hits the FOR loop it complains about no subMeshes, so I had to put another check right before that FOR loop.
Its like there’s some kind of race condition and the mesh changes property within that code block.

Also, it doesn’t happen all the time. Sometimes I gotta move around a lot. If nothing obvious stands out I can try and reproduce in a playground.

I do not see how you can have no subMesh as it is tested Oo

It was happening in that Alien city in my virtual world Threedium (not anymore 'cos of my little hack). I have some intense culling going on so a lot of polygons are hiding and showing when you move about. It would eventually cause a crash in this part of the code. I will try and replicate in a playground

1 Like

This is the problem scene https://www.babylonjs-playground.com/#43KDLX#2

That playground won’t even run properly 'cos I’m getting a lot of these errors in the playground
“Instances should only be created for meshes with geometry”

I can’t see anything wrong with the .babylon file though.

Well I think there is a problem with the tool that generates the .babylon file
It is creating instances of meshes with no geometry

Can you share the source scene?

pinging @Drigax

Its this file https://preview.punkoffice.com/alien/city2.babylon

I cannot find any empty meshes…or maybe I’m not looking hard enough :confused:

How do you create it? Blender?

I used Unity and the Unity exporter to Babylon

I ran in test in the console:
for (var i=0;i<Assets.scene.meshes.length;i++) {var mesh=Assets.scene.meshes[i];var pos=mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);if(pos==null)console.log(mesh.name);}

and I found there are 71 meshes that have no position data so I can see the problem. I will clean that up and see if it works properly now.

ok I fixed it!

I had a trashcan and a rock with no geometry but they had one or two instances attached. I think there was some weird exporting from Unity because Unity can have a lot of empty objects with children and I might’ve had one or two of them as a prefabs so they go converted into instances.

So I’m not sure if this is really a bug because I broke some rules with my .babylon file and that caused the problems.

1 Like

Pinging @MackeyK24: We should not flag instances for meshes with no geometry in the Unity exporter

Actually that code was custom-written by me for my own use.
I had an issue with the existing Unity exporter so I wrote a hack to convert prefabs into instances. This is not part of the original Unity exporter

ok makes sense :slight_smile: so you know how to fix it now :smiley:

We discussed it in this thread Confused about Unity prefabs to Babylonjs instances

I’m still confused by the current method of converting prefabs to instances so I just use my own code for now (which needs a bit of fixing as we discovered)

2 Likes