mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 07:04:31 +00:00
Added guards around context.getImageData
calls in BitmapData, Text and Canvas Tinting classes to avoid crashing restricted browsers like Epic Browser. Please understand that several Phaser features won't work correctly with this browser (thanks @Erik3000 #1714)
This commit is contained in:
parent
ef5c0d89de
commit
36c064511c
5 changed files with 60 additions and 20 deletions
|
@ -97,6 +97,10 @@ or the minified version:
|
|||
|
||||
`<script src="//cdn.jsdelivr.net/phaser/2.3.0/phaser.min.js"></script>`
|
||||
|
||||
[cdnjs.com](https://cdnjs.com/libraries/phaser) also offers a free CDN service. They have all versions of Phaser and even the custom builds:
|
||||
|
||||
`<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.3.0/phaser.js"></script>`
|
||||
|
||||
### Phaser Sandbox
|
||||
|
||||
If you'd like to try coding in Phaser right now, with nothing more than your web browser then you can head over to the [Phaser Sandbox](http://phaser.io/sandbox). You'll find Quick Start templates and a user-friendly editor filled with handy code-completion features.
|
||||
|
@ -244,6 +248,7 @@ Version 2.3.1 - "Katar" - in dev
|
|||
|
||||
### Updates
|
||||
|
||||
* TypeScript definitions fixes and updates (thanks @clark-stevenson @isuda)
|
||||
* Added missing `resumed` method to Phaser.State class template.
|
||||
|
||||
### Bug Fixes
|
||||
|
@ -251,6 +256,8 @@ Version 2.3.1 - "Katar" - in dev
|
|||
* The LoadTexture component has had a redundant `dirty` call removed from it.
|
||||
* TileSprites were missing a `physicsType` property, causing them to not collide with anything (thanks @numbofathma #1702)
|
||||
* Sprite was missing the Health and InCamera components.
|
||||
* A Tween could be incorrectly set to never end if it was given a duration of zero (thanks @hardalias #1710)
|
||||
* Added guards around `context.getImageData` calls in BitmapData, Text and Canvas Tinting classes to avoid crashing restricted browsers like Epic Browser. Please understand that several Phaser features won't work correctly with this browser (thanks @Erik3000 #1714)
|
||||
|
||||
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
|
||||
|
||||
|
|
|
@ -64,9 +64,16 @@ Phaser.BitmapData = function (game, key, width, height) {
|
|||
this.imageData = this.context.getImageData(0, 0, width, height);
|
||||
|
||||
/**
|
||||
* @property {Uint8ClampedArray} data - A Uint8ClampedArray view into BitmapData.buffer.
|
||||
* A Uint8ClampedArray view into BitmapData.buffer.
|
||||
* Note that this is unavailable in some browsers (such as Epic Browser due to its security restrictions)
|
||||
* @property {Uint8ClampedArray} data
|
||||
*/
|
||||
this.data = this.imageData.data;
|
||||
this.data = null;
|
||||
|
||||
if (this.imageData)
|
||||
{
|
||||
this.data = this.imageData.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {Uint32Array} pixels - An Uint32Array view into BitmapData.buffer.
|
||||
|
@ -76,21 +83,24 @@ Phaser.BitmapData = function (game, key, width, height) {
|
|||
/**
|
||||
* @property {ArrayBuffer} buffer - An ArrayBuffer the same size as the context ImageData.
|
||||
*/
|
||||
if (this.imageData.data.buffer)
|
||||
if (this.data)
|
||||
{
|
||||
this.buffer = this.imageData.data.buffer;
|
||||
this.pixels = new Uint32Array(this.buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (window['ArrayBuffer'])
|
||||
if (this.imageData.data.buffer)
|
||||
{
|
||||
this.buffer = new ArrayBuffer(this.imageData.data.length);
|
||||
this.buffer = this.imageData.data.buffer;
|
||||
this.pixels = new Uint32Array(this.buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pixels = this.imageData.data;
|
||||
if (window['ArrayBuffer'])
|
||||
{
|
||||
this.buffer = new ArrayBuffer(this.imageData.data.length);
|
||||
this.pixels = new Uint32Array(this.buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pixels = this.imageData.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,6 +237,11 @@ PIXI.CanvasTinter.checkInverseAlpha = function()
|
|||
// Get the color values
|
||||
var s1 = canvas.context.getImageData(0, 0, 1, 1);
|
||||
|
||||
if (s1 === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Plot them to x2
|
||||
canvas.context.putImageData(s1, 1, 0);
|
||||
|
||||
|
|
|
@ -353,7 +353,7 @@ PIXI.Text.prototype.determineFontProperties = function(fontStyle)
|
|||
{
|
||||
var properties = PIXI.Text.fontPropertiesCache[fontStyle];
|
||||
|
||||
if(!properties)
|
||||
if (!properties)
|
||||
{
|
||||
properties = {};
|
||||
|
||||
|
@ -380,6 +380,17 @@ PIXI.Text.prototype.determineFontProperties = function(fontStyle)
|
|||
context.fillStyle = '#000';
|
||||
context.fillText('|MÉq', 0, baseline);
|
||||
|
||||
if (!context.getImageData(0, 0, width, height))
|
||||
{
|
||||
properties.ascent = baseline;
|
||||
properties.descent = baseline + 6;
|
||||
properties.fontSize = properties.ascent + properties.descent;
|
||||
|
||||
PIXI.Text.fontPropertiesCache[fontStyle] = properties;
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
var imagedata = context.getImageData(0, 0, width, height).data;
|
||||
var pixels = imagedata.length;
|
||||
var line = width * 4;
|
||||
|
@ -390,17 +401,18 @@ PIXI.Text.prototype.determineFontProperties = function(fontStyle)
|
|||
var stop = false;
|
||||
|
||||
// ascent. scan from top to bottom until we find a non red pixel
|
||||
for(i = 0; i < baseline; i++)
|
||||
for (i = 0; i < baseline; i++)
|
||||
{
|
||||
for(j = 0; j < line; j += 4)
|
||||
for (j = 0; j < line; j += 4)
|
||||
{
|
||||
if(imagedata[idx + j] !== 255)
|
||||
if (imagedata[idx + j] !== 255)
|
||||
{
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!stop)
|
||||
|
||||
if (!stop)
|
||||
{
|
||||
idx += line;
|
||||
}
|
||||
|
@ -416,17 +428,18 @@ PIXI.Text.prototype.determineFontProperties = function(fontStyle)
|
|||
stop = false;
|
||||
|
||||
// descent. scan from bottom to top until we find a non red pixel
|
||||
for(i = height; i > baseline; i--)
|
||||
for (i = height; i > baseline; i--)
|
||||
{
|
||||
for(j = 0; j < line; j += 4)
|
||||
for (j = 0; j < line; j += 4)
|
||||
{
|
||||
if(imagedata[idx + j] !== 255)
|
||||
if (imagedata[idx + j] !== 255)
|
||||
{
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!stop)
|
||||
|
||||
if (!stop)
|
||||
{
|
||||
idx -= line;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,11 @@ PIXI.canUseNewCanvasBlendModes = function()
|
|||
context.drawImage(magenta, 0, 0);
|
||||
context.drawImage(yellow, 2, 0);
|
||||
|
||||
if (!context.getImageData(2,0,1,1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = context.getImageData(2,0,1,1).data;
|
||||
|
||||
return (data[0] === 255 && data[1] === 0 && data[2] === 0);
|
||||
|
|
Loading…
Reference in a new issue