question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Couldn't create Texture from resized DOM Image

See original GitHub issue

Describe the bug If the DOM image is resized with CSS, like: width: 10%, and you try to create texture with THREE.Texture(DOM_ELEMENT) class, that will result in: GL ERROR :GL_INVALID_VALUE : glTexSubImage2D: bad dimensions. The behaviour appears since v135. It is not present in v134.

To Reproduce

Steps to reproduce the behavior:

  1. Create a DOM image in HTML
  2. Resize it with CSS: img{width: 10%}
  3. Create a texture from image with THREE.Texture(DomElement) class
  4. Use texture on any material
  5. You will get: GL ERROR :GL_INVALID_VALUE : glTexSubImage2D: bad dimensions. in latest Chrome.

Code

  let material = new THREE.MeshBasicMaterial();
  let img = document.querySelector('img')
  let texture = new THREE.Texture(img)
  texture.needsUpdate = true;
  material.map = texture;
  mesh = new THREE.Mesh( geometry, material );
  scene.add( mesh );

Live example

Expected behavior

To see sphere with kitten texture.

Screenshots

This is the expected result of demo. Screenshot 2022-01-07 at 01 51 56

Platform:

  • Device: Desktop
  • OS: MacOs
  • Browser: Chrome
  • Three.js version: r136

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:24 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
akellacommented, May 17, 2022

Yeah, so, instead of

let texture = new THREE.Texture(DOM_IMG)

I used this workaround:

let image = new Image();
image.src = DOM_IMG.src;
let texture = new THREE.Texture(image);

also in one case this:

let CLONED_IMAGE = DOM_IMG.cloneNode(true); // this helped when i set image width in JS
let texture = new THREE.Texture(CLONED_IMAGE);

But of course, would be perfect to fix issue, to not do this. Or is it best practice now to clone everything from DOM before converting it to texture? 🤔

2reactions
akellacommented, Jan 7, 2022

could asking other developers on discord be a way to make up a decision? For me as one of three.js dev-users it is obvious that i expect three.js to disregard any CSS, when i convert DOM element to WebGL Texture. And my hypothesis is its like that for 99% people. Because those are two different mental models/concepts/coordinate-systems, and i dont want them to interfere.

What are the possible drawbacks of using naturalWidth here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

GL_INVALID_VALUE: Offset overflows texture dimensions
Couldn't create Texture from resized DOM Image ... You potentially have to update your GLSL since the shader always uses the natural dimensions...
Read more >
three js, WebGLRenderer image quality drops on safari
WebGLRenderer: Texture has been resized from (4000x2000) to (2048x1024). camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.
Read more >
Engine Error: Couldn't create Texture/Shader - 887a005 Error
I took the game files for Apex Legends from my mate and after playing for a day, I got the "Cannot create texture"...
Read more >
Image Textures
All this is done on the JavaScript side. The command for creating a texture object is gl.createTexture(). The command in OpenGL 1.1 was...
Read more >
melonjs/public - Gitter
I've been trying to make it work for hours, but I just couldn't ... You need to use a canvas context, or an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found