# thinInstanceCount doesn't seem right when creating with mesh.thinInstanceSetBuffer

**URL:** <https://forum.babylonjs.com/t/thininstancecount-doesnt-seem-right-when-creating-with-mesh-thininstancesetbuffer/29707>\
**Category:** Bugs\
**Created:** [April 26, 2022, 2:17am UTC](https://forum.babylonjs.com/t/thininstancecount-doesnt-seem-right-when-creating-with-mesh-thininstancesetbuffer/29707 "2022-04-26T02:17:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jelster](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jelster/32/25881_2.png) [@jelster](https://forum.babylonjs.com/u/jelster)\
**Post date:** [April 26, 2022, 2:17am UTC](https://forum.babylonjs.com/t/thininstancecount-doesnt-seem-right-when-creating-with-mesh-thininstancesetbuffer/29707/1 "2022-04-26T02:17:58Z")

</div>

Potentially an unintented regression from [here](https://forum.babylonjs.com/t/cant-set-thininstancecount-for-clone/29674), or potentially something different.

This PG - [Space-Truckers: The Scene Optimization! | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#17ZX41#2) - shows via console log output what I’m seeing.

I initially specify 15000 asteroids to be created. Unless I got some array math wrong (not unlikely), I’m getting 4x the number of TI that I asked for - 60000! As part of what I’m working on, the thinInstanceCount gets changed by a custom SceneOptimizer until FPS hits 60. Here’s a sample output log:

```auto
creating count of asteroids 15000
loaded HDRCubeTexture
ready scene
Instance count before optimizing 60000
Reduced asteroid thin instance count
Instance count before optimizing 48000
Reduced asteroid thin instance count
Instance count before optimizing 38400
Reduced asteroid thin instance count
Frame rate stabilized at 60 with 30720 asteroids

```

Normally I’d be the first to ask what I’m doing wrong here, but @RaananW at some point in the past gave me permission to question if it’s something in the engine 🙂 🕶❤

P.S. - Not that I’m objecting to being able to display 60k asteroids, just have no idea where or why that figure is arrived at!

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [April 26, 2022, 3:06am UTC](https://forum.babylonjs.com/t/thininstancecount-doesnt-seem-right-when-creating-with-mesh-thininstancesetbuffer/29707/2 "2022-04-26T03:06:49Z")

</div>

Heya, it looks like the problem is on line 242 where the size of the matrix array is set to numAsteroids \* 64. Since each matrix is size 16 floats, then the size of that array should be numAsteroids \* 16. 🙂

> **[Babylon.js Playground](https://playground.babylonjs.com/#17ZX41%234)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![jelster](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jelster/32/25881_2.png) [@jelster](https://forum.babylonjs.com/u/jelster)\
**Post date:** [April 26, 2022, 5:39am UTC](https://forum.babylonjs.com/t/thininstancecount-doesnt-seem-right-when-creating-with-mesh-thininstancesetbuffer/29707/3 "2022-04-26T05:39:23Z")

</div>

Well gee, I suppose that might have something to do with it! Thanks @Blake - I’d convinced myself that there was somehow a reason for it being 64 but now you mention it… yeah.
