phaser-ce icon indicating copy to clipboard operation
phaser-ce copied to clipboard

text.cacheAsBitmap = true throws error.

Open ankush-badyal opened this issue 7 years ago • 1 comments

This Issue is about (pick one, ✏️ delete others)

  • A bug in the API: Text.cacheAsBitmap
    • Phaser version(s): 2.10.6
    • What should happen: The text should be cached as bitmap
    • What happens instead: Uncaught TypeError: Cannot read property 'renderBuffer' of undefined

Error is in this piece of code -

The below function is not associated with a class so "this.renderBuffer" is not accessible. Possible fix is calling this function using call method and passing "this" as context.

function _CreateFramebuffer (gl, width, height, scaleMode, textureUnit)
{
    var framebuffer = gl.createFramebuffer();
    var depthStencilBuffer = gl.createRenderbuffer();
    var colorBuffer = null;
    var fbStatus = 0;
    gl.activeTexture(gl.TEXTURE0 + textureUnit);
    gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
    gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);
    gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.renderBuffer);
    colorBuffer = _CreateEmptyTexture(gl, width, height, scaleMode);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorBuffer, 0);
    fbStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
    if(fbStatus !== gl.FRAMEBUFFER_COMPLETE)
    {
        console.error('Incomplete GL framebuffer. ', _fbErrors[fbStatus]);
    }
    framebuffer.width = width;
    framebuffer.height = height;
    framebuffer.targetTexture = colorBuffer;
    framebuffer.renderBuffer = depthStencilBuffer;
    return framebuffer;
}

PIXI.FilterTexture = function (gl, width, height, scaleMode, textureUnit)
{
    textureUnit = typeof textureUnit === 'number' ? textureUnit : 0;

    /**
     * @property gl
     * @type WebGLContext
     */
    this.gl = gl;

    // next time to create a frame buffer and texture

    /**
     * @property frameBuffer
     * @type Any
     */
//    this.frameBuffer = _CreateFramebuffer(gl, width, height, scaleMode || PIXI.scaleModes.DEFAULT, textureUnit);
// The below line fixes the error.
this.frameBuffer = _CreateFramebuffer.call (this, gl, width, height, scaleMode || PIXI.scaleModes.DEFAULT, textureUnit);
    /**
     * @property texture
     * @type Any
     */
    this.texture = this.frameBuffer.targetTexture;
    this.width = width;
    this.height = height;
    this.renderBuffer = this.frameBuffer.renderBuffer;
};

ankush-badyal avatar Jun 14 '18 06:06 ankush-badyal

Please also update following line in the Pixi.DisplayObject's _generateCachedSprite function: var renderTexture = new Phaser.RenderTexture(this.game, bounds.width, bounds.height, undefined, undefined, undefined, this.game.renderer, textureUnit);

ankush-badyal avatar Jul 03 '18 13:07 ankush-badyal