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.

WebGL Render Warning if cacheAsBitmap is true

See original GitHub issue

If cacheAsBitmap is set to true on a container that is empty or has only invisible children, Chrome (v56) and Firefox (v49) log a WebGL warning.

Warning Chrome:

[.Offscreen-For-WebGL-0000005524CBB4F0] GL ERROR :GL_INVALID_FRAMEBUFFER_OPERATION : glClear: framebuffer incomplete
[.Offscreen-For-WebGL-0000005524CBB4F0] RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering.

Warning Firefox:

Error: WebGL: clear: Incomplete framebuffer: Status 0x8cd6: COLOR_ATTACHMENT0 has no width or height.
Error: 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.

Example: https://codepen.io/anon/pen/PWrXOB

Actual use-case: I have a container with n sprite elements. Depending on the state of the application I want to show 0 to n of the elements (by setting visible to true/false). After updating which sprites are visible, the container can be cached. If all elements are set to invisible the warnings appear.

My suggestion would be to extend the condition in DisplayObject.prototype._renderCachedWebGL (and maybe in DisplayObject.prototype._renderCachedCanvas to be consistent) to include a check for width and height of the element.

if (!this.visible || this.worldAlpha <= 0 || !this.renderable)
{
  return;
}

to

if (!this.visible || this.worldAlpha <= 0 || !this.renderable || this.width === 0 || this.height === 0)
{
  return;
}

I can create a Pull request if you like the solution but I wanted to discuss it first as I am not sure if it’s the only/best place for a fix.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jsficommented, Feb 21, 2017

Maybe I understand something wrong, but aren’t the bounds used to generate the texture?

https://github.com/pixijs/pixi.js/blob/dev/src/extras/cacheAsBitmap.js#L186

If either width or height are zero, the texture should be empty. So by checking width and height first, it is possible to step over lines 178 to 205 and create the sprite without texture (which will automatically use Texture.Empty https://github.com/pixijs/pixi.js/blob/dev/src/core/sprites/Sprite.js#L103)

1reaction
ivanpopelyshevcommented, Feb 21, 2017

I’m not sure that bounds won’t be changed later. Its better to add flag to cached object that renderTexture is empty, or may be reference Texture.EMPTY instead, and then check it in rendering method

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebGL Render Warning if cacheAsBitmap is true · Issue #3767
If cacheAsBitmap is set to true on a container that is empty or has only invisible children, Chrome (v56) and Firefox (v49) log...
Read more >
deprecation.js - PixiJS API Documentation
warn ('graphics generate texture has moved to the renderer. ' + 'Or to render a graphics to a texture using canvas please use...
Read more >
WebGL best practices - Web APIs - MDN Web Docs - Mozilla
This page tackles recommendations across the spectrum of expertise, and not only highlights dos and don'ts, but also details why. You can rely ......
Read more >
How does the render work? - Pixi.js - HTML5 Game Devs Forum
I'm putting all the tiles & ports to the same container then using `cacheAsBitmap = true` on the container but the resolution goes...
Read more >
Games Optimisations Tips | RPG Maker Forums
The WebGL renderer is way faster than the canvas renderer. ... Setting cacheAsBitmap to true turns an object into a sprite by caching...
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