1

I am trying to assign an image to the texture and sometimes it causes the next error reports:

WebGL: texImage2D: Failed to get data from DOM element. Implicit width and height for this upload will be zero

WebGL: drawElements: Active texture 0 for target 0x0de1 is 'incomplete', and will be rendered as RGBA(0,0,0,1), as per the GLES 2.0.24 $3.8.2: The dimensions of level_base are not all positive

When I reload the page the texture appears normally.

I have realized that it occurs only in Firefox and it seems that the image is not processed completely. Is there any way to check is the image ready to be processed or a workaround for this issue.

Thank you in advance and sorry for my bad English.

UPDATE: I create a framework with a pretty complicated architecture so there is a very simplified version of the code:

1. I create a texture wrapper that contains an instance of WebGL texture object.

function Texture (gl) {
// Here the texture does not keep any data.
this.texture = gl.createTexture();

};

2. When it is needed the texture gets an instance of image and performs default initialization procedure:

function initializeTexture (image) {
gl.bindTexture(gl.TEXTURE_2D, this.texture);

// Set pixel storing mode.
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);

// Pass image data into the texture.
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, image);

// Handle mipmapping option.
if (this.enableMipmap &&
    Math.isPowerOfTwo(this.width) &&
    Math.isPowerOfTwo(this.height)) {
    gl.generateMipmap(gl.TEXTURE_2D);
}

// Set filtering modes.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.magFilter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.minFilter);

// Set wrapping modes.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.wrapS);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.wrapT);

// Unbind the texture.
gl.bindTexture(gl.TEXTURE_2D, null);

}

3. In game loop there is another default set of actions:

function applyTexture (value) {
// Pass the texture into shader program.
gl.uniform1i(uniform.location, uniform.id);

// Activate the texture.
gl.activeTexture(gl.TEXTURE0 + uniform.id);

// Bind passed texture.
gl.bindTexture(gl.TEXTURE_2D, value.texture);

};

Eugene
  • 11
  • 1
  • 3
  • 2
    Do you wait for the `load` event on the image? – Kirill Dmitrenko Sep 12 '16 at 06:05
  • 1
    Is this helpful? http://stackoverflow.com/questions/19722247/webgl-wait-for-texture-to-load – gman Sep 12 '16 at 06:18
  • @Kirill, yes, I load images the standard way but the issue occurs when I use external image or procedurally generated one. – Eugene Sep 12 '16 at 12:35
  • @gman, thanks for the answer, but, unfortunately, it did not help me. – Eugene Sep 12 '16 at 12:35
  • @Eugene I've found [the place in FF source code](https://dxr.mozilla.org/mozilla-esr45/source/dom/canvas/WebGLTextureUpload.cpp#272), which generates the error. However, it's somewhat cumbersome. Can you provide a snippet of your code? Or elaborate a bit upon what external images exactly are? – Kirill Dmitrenko Sep 12 '16 at 15:02
  • Yes, please post your code (the smallest sample possible that repos the issue) – gman Sep 12 '16 at 15:40
  • @Kirill By 'external image' I mean an image file on a server, but not created programmatically on a client-side. Sorry for misunderstanding. – Eugene Sep 12 '16 at 23:06

1 Answers1

0

WebGL: texImage2D: Failed to get data from DOM element. Implicit width and height for this upload will be zero

This is straightforward: texImage2D failed to get any data from your image element. Usually this is because the image hasn't loaded its current src yet.

When I reload the page the texture appears normally.

This sort of bug is almost always due to not correctly waiting until the image is loaded, since on subsequent loads, the image's data is generally retrieved from the http cache, causing the load to be almost immediate.

Is there any way to check is the image ready to be processed or a workaround for this issue.

The 'load' event, as linked by @gman: WebGL - wait for texture to load

Jeff Gilbert
  • 406
  • 2
  • 4