# 'updateTextureData' not work when the texture is not link to a material

**URL:** <https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341>\
**Category:** Bugs\
**Tags:** material\
**Created:** [August 25, 2021, 11:21am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341 "2021-08-25T11:21:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsAndy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wsandy/32/16904_2.png) [@wsAndy](https://forum.babylonjs.com/u/wsAndy)\
**Post date:** [August 25, 2021, 11:21am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/1 "2021-08-25T11:21:12Z")

</div>

hello everyone,

I want to update a part of texture and find that ‘engine.updateTextureData()’ is a good choise.

However, when the texture is not link to any material, ‘engine.updateTextureData()’ will not work.  
Here is the PG. [https://playground.babylonjs.com/#EVX1DH#45](https://playground.babylonjs.com/#EVX1DH#45)  
When I delete line 71, ‘engine.updateTextureData’ will not work.

Thanks.

---

<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:** [August 26, 2021, 11:22am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/2 "2021-08-26T11:22:26Z")

</div>

I don’t think this method is really meant to be called by the end user…

Anyway, to make it work you must bind the texture first:

[https://playground.babylonjs.com/#EVX1DH#55](https://playground.babylonjs.com/#EVX1DH#55)

---

<div class="post-metadata">

**Author:** ![wsAndy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wsandy/32/16904_2.png) [@wsAndy](https://forum.babylonjs.com/u/wsAndy)\
**Post date:** [August 26, 2021, 12:58pm UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/3 "2021-08-26T12:58:54Z")

</div>

Thanks!  
‘engine.\_bindTextureDirectly’ is necessary

---

<div class="post-metadata">

**Author:** ![wsAndy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wsandy/32/16904_2.png) [@wsAndy](https://forum.babylonjs.com/u/wsAndy)\
**Post date:** [August 27, 2021, 6:12am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/4 "2021-08-27T06:12:27Z")

</div>

I find a new problem here,  
in PG( [https://playground.babylonjs.com/#EVX1DH#60](https://playground.babylonjs.com/#EVX1DH#60) ), I could update three part of image .  
but in PG( [https://playground.babylonjs.com/#EVX1DH#62](https://playground.babylonjs.com/#EVX1DH#62) ), only one part region could be updated.  
it’s realy strange

---

<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:** [August 27, 2021, 9:25am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/5 "2021-08-27T09:25:04Z")

</div>

You have some errors in the console log in the 2nd PG:

```auto
babylon.js:16 WebGL: INVALID_OPERATION: texSubImage2D: ArrayBufferView
not big enough for request

```

That’s because the subarray you extract is not big enough given the width/height of the texture you want to update (`region.width * 0.5` and `region.height * 0.5`).

---

<div class="post-metadata">

**Author:** ![wsAndy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wsandy/32/16904_2.png) [@wsAndy](https://forum.babylonjs.com/u/wsAndy)\
**Post date:** [August 30, 2021, 3:47am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/6 "2021-08-30T03:47:16Z")

</div>

[https://playground.babylonjs.com/#EVX1DH#63](https://playground.babylonjs.com/#EVX1DH#63)

Sorry, I don’t understand. the subarray return an array with 37500 length, and the texture I want to update is 250x150. why this array is not big enough?

---

<div class="post-metadata">

**Author:** ![wsAndy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wsandy/32/16904_2.png) [@wsAndy](https://forum.babylonjs.com/u/wsAndy)\
**Post date:** [August 30, 2021, 4:02am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/7 "2021-08-30T04:02:46Z")

</div>

I find the reason.

[Here](https://stackoverflow.com/questions/42789896/webgl-error-arraybuffer-not-big-enough-for-request-in-case-of-gl-luminance)  
The width or height cannot divide by 4, I need add **gl.pixelStorei(gl.UNPACK\_ALIGNMENT, 1);**

---

<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:** [August 30, 2021, 9:01am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/8 "2021-08-30T09:01:59Z")

</div>

I don’t know how to handle this one as I don’t know much of openGL…

After having read some docs, I think we could set the UNPACK\_ALIGMENT to 1 in the whole engine as I think our buffers are always tightly packed (we only set it to 1 in the raw texture class when width can’t be divided by 4, and we don’t reset it to 4 afterward, meaning it stays to 1). But it’s not what we are doing, so I prefer @sebavan having a look at that.

As a quick fix, you can call `pixelStorei` yourself:  
[https://playground.babylonjs.com/#EVX1DH#64](https://playground.babylonjs.com/#EVX1DH#64)

---

<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:** [August 30, 2021, 10:46am UTC](https://forum.babylonjs.com/t/updatetexturedata-not-work-when-the-texture-is-not-link-to-a-material/23341/9 "2021-08-30T10:46:44Z")

</div>

@Evgeni_Popov I agree we should be able to set it to 1 on start ??? what do you think
