# Error from copyTextureToTexture (Overload resolution)

**URL:** <https://discourse.threejs.org/t/error-from-copytexturetotexture-overload-resolution/65836>\
**Category:** Questions\
**Tags:** render-target, textures\
**Created:** [May 22, 2024, 12:15am UTC](https://discourse.threejs.org/t/error-from-copytexturetotexture-overload-resolution/65836 "2024-05-22T00:15:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichFWebb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/richfwebb/32/28746_2.png) [@RichFWebb](https://discourse.threejs.org/u/RichFWebb)\
**Post date:** [May 22, 2024, 12:15am UTC](https://discourse.threejs.org/t/error-from-copytexturetotexture-overload-resolution/65836/1 "2024-05-22T00:15:00Z")

</div>

I want to use copyTextureToTexture, but get this error:

TypeError: Failed to execute ‘texSubImage2D’ on ‘WebGL2RenderingContext’: Overload resolution failed."

I’m using a render target as the source, on r160.

Full example:  
[https://jsfiddle.net/waqt65y7/](https://jsfiddle.net/waqt65y7/)

---

<div class="post-metadata">

**Author:** ![RichFWebb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/richfwebb/32/28746_2.png) [@RichFWebb](https://discourse.threejs.org/u/RichFWebb)\
**Post date:** [May 22, 2024, 5:15am UTC](https://discourse.threejs.org/t/error-from-copytexturetotexture-overload-resolution/65836/3 "2024-05-22T05:15:49Z")

</div>

On line 2414 of WebGLRenderer in r160, renderer.copyTextureToTexture does:

````
```_gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );```

````

which is a WebGL1 signature removed in WebGL2:  
texSubImage2D(target, level, xoffset, yoffset, format, type, pixels)  
So it’s just missing the width and height parameters.

Is that a mistake?

---

<div class="post-metadata">

**Author:** ![PavelBoytchev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/pavelboytchev/32/38639_2.png) [@PavelBoytchev](https://discourse.threejs.org/u/PavelBoytchev)\
**Post date:** [May 22, 2024, 8:39pm UTC](https://discourse.threejs.org/t/error-from-copytexturetotexture-overload-resolution/65836/4 "2024-05-22T20:39:19Z")

</div>

I’ve never been in this part of Three.js, so the next two sentences might be wrong:

For your scenario, would it be possible to use `.copyFramebufferToTexture` instead of `.copyTextureToTexture`? When I try it there is no error … but also nothing is shown on the screen (maybe because the demo is not complete?)

PS. When I check the render target texture, it has no image. I don’t know whether this is OK or not. The `.image` property usually appears when a texture is loaded from file. For fremebuffer textures it might be different situation.

---

<div class="post-metadata">

**Author:** ![RichFWebb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/richfwebb/32/28746_2.png) [@RichFWebb](https://discourse.threejs.org/u/RichFWebb)\
**Post date:** [May 22, 2024, 9:47pm UTC](https://discourse.threejs.org/t/error-from-copytexturetotexture-overload-resolution/65836/5 "2024-05-22T21:47:44Z")

</div>

If I click the jsfiddle link, I immediately see this error. Is it different for you?

 ![Screenshot from 2024-05-22 17-42-27](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/0/8/081f6336ffb6da598d5f93a286100aaab9ada4bc.png)

Copy framebuffer did not work for me, but I did find a workaround doing this:

```javascript
renderer.readRenderTargetPixels( target, 0, 0, size, size, buffer );
new THREE.DataTexture(buffer, size, size);

```

I think this is a mistake in the threejs code though.

---

<div class="post-metadata">

**Author:** ![PavelBoytchev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/pavelboytchev/32/38639_2.png) [@PavelBoytchev](https://discourse.threejs.org/u/PavelBoytchev)\
**Post date:** [May 22, 2024, 10:03pm UTC](https://discourse.threejs.org/t/error-from-copytexturetotexture-overload-resolution/65836/6 "2024-05-22T22:03:12Z")

</div>

> [@RichFWebb](#):
>
> If I click the jsfiddle link, I immediately see this error. Is it different for you?

Yes.  
With `.copyTextureToTexture` I see the same error message.  
With `.copyFramebufferToTexture` I see no error message.

It’s good that you’ve found a workaround that works for you. If you think this is a bug in Three.js, it is better to post it in the [Three.js issue tracker on Github](https://github.com/mrdoob/three.js/issues).

However, also look at [WebGLRenderer: Calling "copyTextureToTexture" on an unused WebGLRenderTarget does nothing · Issue #28282 · mrdoob/three.js · GitHub](https://github.com/mrdoob/three.js/issues/28282#issuecomment-2095437930)

---

<div class="post-metadata">

**Author:** ![RichFWebb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/richfwebb/32/28746_2.png) [@RichFWebb](https://discourse.threejs.org/u/RichFWebb)\
**Post date:** [May 23, 2024, 12:18am UTC](https://discourse.threejs.org/t/error-from-copytexturetotexture-overload-resolution/65836/7 "2024-05-23T00:18:18Z")

</div>

Thanks for the relevant info, but in this case it’s clear that the target _is_ initialized since calling renderer.setTarget and then renderer.render before copyTextureToTexture. I’ll put an issue up on github.
