Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text.cacheAsBitmap = true throws error. #551

Open
ankush-badyal opened this issue Jun 14, 2018 · 1 comment
Open

text.cacheAsBitmap = true throws error. #551

ankush-badyal opened this issue Jun 14, 2018 · 1 comment
Labels

Comments

@ankush-badyal
Copy link

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
Copy link
Author

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);

@samme samme added the bug label May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants