Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vpmedia committed Oct 11, 2024
1 parent 55517f3 commit b145e01
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @vpmedia/phaser

[![npm version](https://badge.fury.io/js/@vpmedia%2Fphaser.svg?v=1.45.0)](https://badge.fury.io/js/@vpmedia%2Fphaser)
[![npm version](https://badge.fury.io/js/@vpmedia%2Fphaser.svg?v=1.46.0)](https://badge.fury.io/js/@vpmedia%2Fphaser)
[![Node.js CI](https://github.com/vpmedia/phaser/actions/workflows/ci.yml/badge.svg)](https://github.com/vpmedia/phaser/actions/workflows/ci.yml)

@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2.
Expand Down
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vpmedia/phaser",
"version": "1.45.0",
"version": "1.46.0",
"description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
"author": "Andras Csizmadia <[email protected]> (www.vpmedia.hu)",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/phaser/core/animation_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class AnimationManager {
this.sprite.setFrame(this.currentFrame);
}
} else {
this.game.exceptionHandler(new Error('Cannot set frame'), { key: value });
this.game.exceptionHandler(new Error('Cannot set frame'), { 'asset.key': value });
}
}

Expand All @@ -332,7 +332,7 @@ export class AnimationManager {
this.sprite.setFrame(this.currentFrame);
}
} else {
this.game.exceptionHandler(new Error('Cannot set frameName'), { key: value });
this.game.exceptionHandler(new Error('Cannot set frameName'), { 'asset.key': value });
}
}
}
8 changes: 1 addition & 7 deletions src/phaser/core/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,7 @@ export class Game {
isWebGlReady = true;
} catch (e) {
isWebGlReady = false;
const tags = {
'document.readyState': document.readyState,
'document.hidden': document.hidden,
'document.visibilityState': document.visibilityState,
'canvas.width': this.canvas.width,
'canvas.height': this.canvas.height,
};
const tags = {};
if (window.PhaserRegistry?.GL_PROGRAM_INFO_LOG) {
tags.gl_program_log = window.PhaserRegistry.GL_PROGRAM_INFO_LOG;
}
Expand Down
3 changes: 2 additions & 1 deletion src/phaser/core/sound_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class SoundManager {
this.context === null ||
(this.context && this.context.createGain === undefined && this.context.createGainNode === undefined)
) {
this.game.exceptionHandler(new Error('Error creating AudioContext'));
this.noAudio = true;
return;
}
Expand Down Expand Up @@ -220,7 +221,7 @@ export class SoundManager {
this.game.cache.decodedSound(key, buffer);
})
.catch((e) => {
this.game.exceptionHandler(e, { key });
this.game.exceptionHandler(e, { 'asset.key': key });
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/phaser/display/canvas/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class CanvasRenderer {
this.view = game.canvas;
this.context = this.view.getContext('2d', { alpha: this.transparent });
if (!this.context) {
throw new Error('Error creating Canvas 2D context.');
throw new Error('Error creating Canvas2D context');
}
this.refresh = true;
this.count = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/phaser/display/display_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class DisplayObject {
const index1 = this.getChildIndex(child);
const index2 = this.getChildIndex(child2);
if (index1 < 0 || index2 < 0) {
throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller.');
throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller');
}
this.children[index1] = child2;
this.children[index2] = child;
Expand Down
2 changes: 1 addition & 1 deletion src/phaser/display/webgl/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class WebGLRenderer {
this.gl = gl;
if (!gl) {
// fail, not able to get a context
throw new Error('This browser does not support WebGL. Try using the Canvas 2D.');
throw new Error('Error creating WebGL context');
}
this.initRegistry();
this.glContextId = window.PhaserRegistry.GL_CONTEXT_ID;
Expand Down
10 changes: 6 additions & 4 deletions src/phaser/display/webgl/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export function compileShader(gl, shaderSrc, shaderType) {
gl.shaderSource(shader, src);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
if (window.PhaserRegistry) {
window.PhaserRegistry.GL_SHADER_INFO_LOG = gl.getShaderInfoLog(shader);
if (!window.PhaserRegistry) {
window.PhaserRegistry = {};
}
window.PhaserRegistry.GL_SHADER_INFO_LOG = gl.getShaderInfoLog(shader);
return null;
}
return shader;
Expand Down Expand Up @@ -65,9 +66,10 @@ export function compileProgram(gl, vertexSrc, fragmentSrc) {
gl.linkProgram(shaderProgram);

if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
if (window.PhaserRegistry) {
window.PhaserRegistry.GL_PROGRAM_INFO_LOG = gl.getProgramInfoLog(shaderProgram);
if (!window.PhaserRegistry) {
window.PhaserRegistry = {};
}
window.PhaserRegistry.GL_PROGRAM_INFO_LOG = gl.getProgramInfoLog(shaderProgram);
}
return shaderProgram;
}
2 changes: 1 addition & 1 deletion src/phaser/geom/util/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export function centroid(points, output = null) {
const result = output || new Point();
const pointsLen = points.length;
if (pointsLen < 1) {
throw new Error('Point(points) array must not be empty.');
throw new Error('Point(points) array must not be empty');
}
if (pointsLen === 1) {
result.copyFrom(points[0]);
Expand Down

0 comments on commit b145e01

Please sign in to comment.