From af66b49f31ebdd23a3ebb9a6601d2e243e9f331e Mon Sep 17 00:00:00 2001 From: photonstorm Date: Wed, 6 May 2015 16:50:10 +0100 Subject: [PATCH] If a BitmapData is created with a width or height set to zero then the width and/or height are set to a default value (256) instead to avoid getContext errors. --- README.md | 1 + src/gameobjects/BitmapData.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6d91a0111..0ce933f26 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,7 @@ Version 2.4 - "Katar" - in dev * SoundManager.volume now has its input value clamped to ensure it's between 0 and 1 (inclusive) * Removed `Input.moveCallback` and `Input.moveCallbackContext` as neither are used any longer. Use `Input.addMoveCallback`. * SoundManager now uses the new `Touch.addTouchLockCallback` methods to handle mobile device audio unlocking. +* If a BitmapData is created with a width or height set to zero then the width and/or height are set to a default value (256) instead to avoid getContext errors. ### Bug Fixes diff --git a/src/gameobjects/BitmapData.js b/src/gameobjects/BitmapData.js index 34a7d9497..ab2c7a065 100644 --- a/src/gameobjects/BitmapData.js +++ b/src/gameobjects/BitmapData.js @@ -13,13 +13,13 @@ * @constructor * @param {Phaser.Game} game - A reference to the currently running game. * @param {string} key - Internal Phaser reference key for the BitmapData. -* @param {number} [width=256] - The width of the BitmapData in pixels. -* @param {number} [height=256] - The height of the BitmapData in pixels. +* @param {number} [width=256] - The width of the BitmapData in pixels. If undefined or zero it's set to a default value. +* @param {number} [height=256] - The height of the BitmapData in pixels. If undefined or zero it's set to a default value. */ Phaser.BitmapData = function (game, key, width, height) { - if (typeof width === 'undefined') { width = 256; } - if (typeof height === 'undefined') { height = 256; } + if (typeof width === 'undefined' || width === 0) { width = 256; } + if (typeof height === 'undefined' || height === 0) { height = 256; } /** * @property {Phaser.Game} game - A reference to the currently running game.