Skip to content

Commit

Permalink
Fix #307 Calling canvas.getContext("bitmaprenderer") with spectorjs p…
Browse files Browse the repository at this point in the history
…lugin enabled causes error.
  • Loading branch information
sebavan committed May 28, 2024
1 parent 8c11f4d commit ffac5e9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions documentation/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Once ```npm start``` has been launched, you can access the following samples to
1. [Exception](http://localhost:1337/sample/index.html?sample=lightsException): Test of exception during capture.
2. [No Render](http://localhost:1337/sample/index.html?sample=lightsNoRender): Test to capture if no frame are detected.
3. [No command](http://localhost:1337/sample/index.html?sample=simpleNoCommand): Simple use case containing a frame with no webgl commands.
4. [Bitmap Renderer](http://localhost:1337/sample/index.html?sample=bitmapRenderer): Do not crash when bitmap renderer is requested.

### Valid Use Cases
1. [Simple](http://localhost:1337/sample/index.html?sample=simple): A basic use case validating state changes.
Expand Down
3 changes: 3 additions & 0 deletions documentation/changeLogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
## Change Log
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.

## v0.9.31
* Fix [Request Non GL contexts](https://github.com/BabylonJS/Spector.js/issues/307)

## v0.9.30
* Fix [Scissor function call](https://github.com/BabylonJS/Spector.js/issues/266)
* Fix [bufferSubData and getAttribLocation number report](https://github.com/BabylonJS/Spector.js/issues/262)
Expand Down
2 changes: 1 addition & 1 deletion extensions/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"minimum_chrome_version": "20",
"name" : "Spector.js",
"version" : "0.9.30",
"version" : "0.9.31",
"homepage_url": "http://spector.babylonjs.com/",
"description" : "Explore and Troubleshoot your WebGL scenes easily.",
"author": "@SpectorJS",
Expand Down
4 changes: 2 additions & 2 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": "spectorjs",
"version": "0.9.30",
"version": "0.9.31",
"description": "Explore and Troubleshoot your WebGL scenes easily.",
"keywords": [
"webgl",
Expand Down
21 changes: 21 additions & 0 deletions sample/js/bitmapRenderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function start() {
const canvas = document.getElementById("renderCanvas");
const r = canvas.getContext("bitmaprenderer");

const offscreen = new OffscreenCanvas(300,150);
const gl = offscreen.getContext("webgl2");

draw();

function draw(t){
gl.clearColor(1,0,0,1);
gl.clear(gl.COLOR_BUFFER_BIT);

const bitmap = offscreen.transferToImageBitmap();
r.transferFromImageBitmap(bitmap);

requestAnimationFrame(draw);
}
}

start();
11 changes: 9 additions & 2 deletions src/backend/spies/canvasSpy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ export class CanvasSpy {
OriginFunctionHelper.executeOriginFunction(this, "getContext", arguments) :
OriginFunctionHelper.executePrototypeOriginFunction(this, OriginalCanvasConstructor, "getContext", arguments);

if (arguments.length > 0 && arguments[0] === "2d") {
return context;
if (arguments.length > 0) {
const contextType = arguments[0];
if (contextType !== "webgl" &&
contextType !== "experimental-webgl" &&
contextType !== "webgl2" &&
contextType !== "experimental-webgl2"
) {
return context;
}
}

if (context) {
Expand Down

0 comments on commit ffac5e9

Please sign in to comment.