Skip to content

Commit ffac5e9

Browse files
committed
Fix #307 Calling canvas.getContext("bitmaprenderer") with spectorjs plugin enabled causes error.
1 parent 8c11f4d commit ffac5e9

File tree

7 files changed

+38
-6
lines changed

7 files changed

+38
-6
lines changed

documentation/build.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Once ```npm start``` has been launched, you can access the following samples to
2929
1. [Exception](http://localhost:1337/sample/index.html?sample=lightsException): Test of exception during capture.
3030
2. [No Render](http://localhost:1337/sample/index.html?sample=lightsNoRender): Test to capture if no frame are detected.
3131
3. [No command](http://localhost:1337/sample/index.html?sample=simpleNoCommand): Simple use case containing a frame with no webgl commands.
32+
4. [Bitmap Renderer](http://localhost:1337/sample/index.html?sample=bitmapRenderer): Do not crash when bitmap renderer is requested.
3233

3334
### Valid Use Cases
3435
1. [Simple](http://localhost:1337/sample/index.html?sample=simple): A basic use case validating state changes.

documentation/changeLogs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
## Change Log
55
Please, find below the per release summary of the contribution added to the project per version. Each of the listed versions is having its corresponding tag in the repo.
66

7+
## v0.9.31
8+
* Fix [Request Non GL contexts](https://github.com/BabylonJS/Spector.js/issues/307)
9+
710
## v0.9.30
811
* Fix [Scissor function call](https://github.com/BabylonJS/Spector.js/issues/266)
912
* Fix [bufferSubData and getAttribLocation number report](https://github.com/BabylonJS/Spector.js/issues/262)

extensions/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"minimum_chrome_version": "20",
44
"name" : "Spector.js",
5-
"version" : "0.9.30",
5+
"version" : "0.9.31",
66
"homepage_url": "http://spector.babylonjs.com/",
77
"description" : "Explore and Troubleshoot your WebGL scenes easily.",
88
"author": "@SpectorJS",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spectorjs",
3-
"version": "0.9.30",
3+
"version": "0.9.31",
44
"description": "Explore and Troubleshoot your WebGL scenes easily.",
55
"keywords": [
66
"webgl",

sample/js/bitmapRenderer.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function start() {
2+
const canvas = document.getElementById("renderCanvas");
3+
const r = canvas.getContext("bitmaprenderer");
4+
5+
const offscreen = new OffscreenCanvas(300,150);
6+
const gl = offscreen.getContext("webgl2");
7+
8+
draw();
9+
10+
function draw(t){
11+
gl.clearColor(1,0,0,1);
12+
gl.clear(gl.COLOR_BUFFER_BIT);
13+
14+
const bitmap = offscreen.transferToImageBitmap();
15+
r.transferFromImageBitmap(bitmap);
16+
17+
requestAnimationFrame(draw);
18+
}
19+
}
20+
21+
start();

src/backend/spies/canvasSpy.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ export class CanvasSpy {
2626
OriginFunctionHelper.executeOriginFunction(this, "getContext", arguments) :
2727
OriginFunctionHelper.executePrototypeOriginFunction(this, OriginalCanvasConstructor, "getContext", arguments);
2828

29-
if (arguments.length > 0 && arguments[0] === "2d") {
30-
return context;
29+
if (arguments.length > 0) {
30+
const contextType = arguments[0];
31+
if (contextType !== "webgl" &&
32+
contextType !== "experimental-webgl" &&
33+
contextType !== "webgl2" &&
34+
contextType !== "experimental-webgl2"
35+
) {
36+
return context;
37+
}
3138
}
3239

3340
if (context) {

0 commit comments

Comments
 (0)