# convertToUnIndexedMesh Bug when VertexBuffer.type is not float

**URL:** <https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-type-is-not-float/50503>\
**Category:** Bugs\
**Created:** [May 13, 2024, 10:24am UTC](https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-type-is-not-float/50503 "2024-05-13T10:24:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moriy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/moriy/32/30563_2.png) [@Moriy](https://forum.babylonjs.com/u/Moriy)\
**Post date:** [May 13, 2024, 10:24am UTC](https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-type-is-not-float/50503/1 "2024-05-13T10:24:47Z")

</div>

I have a gltf file , it can be correctly loaded by gltf-loader.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/4/e4a4dc764b92fde9e23368f57856689c338c273d.jpeg)  
After PrepareMeshForTrianglesAndVerticesMode, it is disappeared and some Console throw some gl error.  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/7/6780c189d44fa7030c39645eae376cc81da8abc9.png)

I print VertexBuffer after PrepareMeshForTrianglesAndVerticesMode, most of values in buffer are NaN

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/d/1/d155ad91d09e815c04acc56af70b36aa46f24ecb.png)  
I review code of PrepareMeshForTrianglesAndVerticesMode, I find stride number is too big and index are out of range (no error , value is set with NaN).  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/a/2a584cbcbe163812091a1bce87482472775977ee.png)  
I replace vertexBuffer.getStrideSize() with (vertexBuffer as any).\_size, it work again.  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/7/b795039b5c39b06c1e47860432788428cb7fd4ce.png)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 13, 2024, 10:51pm UTC](https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-type-is-not-float/50503/2 "2024-05-13T22:51:42Z")

</div>

Would be great if you could share a repro ?

Adding @bghgary in case it raises a flag

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [May 13, 2024, 11:42pm UTC](https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-type-is-not-float/50503/3 "2024-05-13T23:42:24Z")

</div>

I think these two numbers (`getStrideSize()` and `_size`) should be the same for a glTF. A repro would be really useful.

---

<div class="post-metadata">

**Author:** ![Moriy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/moriy/32/30563_2.png) [@Moriy](https://forum.babylonjs.com/u/Moriy)\
**Post date:** [May 14, 2024, 1:18am UTC](https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-type-is-not-float/50503/4 "2024-05-14T01:18:35Z")

</div>

Here is the error gltf file, you can load and use PrepareMeshForTrianglesAndVerticesMode for it to repro this issuse  
[https://moriyer.github.io/BabylonTexture/GLTF/box](https://moriyer.github.io/BabylonTexture/GLTF/box) (1).gltf  
@bghgary @sebavan

---

<div class="post-metadata">

**Author:** ![Moriy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/moriy/32/30563_2.png) [@Moriy](https://forum.babylonjs.com/u/Moriy)\
**Post date:** [May 14, 2024, 1:27am UTC](https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-type-is-not-float/50503/5 "2024-05-14T01:27:28Z")

</div>

This file’s position/uv/normal are float64Array, their byte stride are 32 (3 \* 4 / 3 \* 8) . float32array’s stride should be 16 (3 \* 4/3 \* 4)  
they use this way to get floatData:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/4/74a30fae8a856ef9c549b3de6958d776fd79e9e8.png)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 14, 2024, 9:52am UTC](https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-type-is-not-float/50503/6 "2024-05-14T09:52:40Z")

</div>

There’s a bug in `_convertToUnIndexedMesh` indeed, here’s the fix:

> <https://github.com/BabylonJS/Babylon.js/pull/15096>
>
> See https://forum.babylonjs.com/t/converttounindexedmesh-bug-when-vertexbuffer-t…ype-is-not-float/50503
