Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspected context is injected with enumerable properties. #134

Open
parasyte opened this issue Aug 26, 2015 · 1 comment
Open

Inspected context is injected with enumerable properties. #134

parasyte opened this issue Aug 26, 2015 · 1 comment

Comments

@parasyte
Copy link

In my js13k game I am doing Very Bad Things to save precious bytes. One such thing is creating a hash of all available methods like so:

var tmp = []
for (i in gl) {
    // First, filter the methods into an array
    gl[i].bind && tmp.push(i)
}
for (i in tmp.sort()) {
    // Then map the sorted methods into the array
    gl[i] = gl[tmp[i]].bind(gl)
}

This code injects its own new properties (numeric indices) in a deterministic manner, which satisfies a need for additional minification. E.g.:

gl[0] === gl.activeTexture
gl[3] === gl.bindBuffer
gl[101] === gl.texImage2D
// ... etc

When the inspector is enabled, the context returned to the application is given a lot of new enumerable properties, which breaks the determinism of the above code. (The code itself is not deterministic, as it relies on a vanilla WebGL context.)

Some examples of the new enumerable properties are:

gl.captureCallback
gl.errorMap
gl.rawgl // oh hey, it's the original context that I wanted originally
gl.enabledExtensions
// ...

See:

this.options = options;
this.canvas = canvas;
this.rawgl = rawgl;
this.isWrapped = true;
this.notifier = new host.Notifier();
this.rawgl.canvas = canvas;
gli.info.initialize(this.rawgl);
this.attributes = rawgl.getContextAttributes ? rawgl.getContextAttributes() : {};
this.statistics = new host.Statistics();
this.frameNumber = 0;
this.inFrame = false;
// Function to call when capture completes
this.captureCallback = null;
// Frame range to capture (inclusive) - if inside a capture window, captureFrame == true
this.captureFrameStart = null;
this.captureFrameEnd = null;
this.captureFrame = false;
this.currentFrame = null;
this.errorMap = {};
this.enabledExtensions = [];
this.frameCompleted = new gli.EventSource("frameCompleted");
this.frameCompleted.addListener(this, function() {
frameSeparator(this);
});

IMHO, this isn't so much a bug that is bad because it breaks silly things like what I'm doing. It's more of an issue that it exposes the WebGL Inspector to the application, and violates the following claim in the readme: https://github.com/benvanik/WebGL-Inspector/blame/master/readme.md#L15

Non-destructive to host page - everything happens in a separate GL context

@greggman
Copy link
Contributor

greggman commented Jan 11, 2017

I've got this in my todo list to deal with.

Currently all of these are stuck on the context which means they could conflict with things user programs are doing

gl.captureCallback
gl.captureFrame
gl.captureFrameEnd
gl.captureFrameStart
gl.enabledExtensions
gl.errorMap
gl.ui
gl.rawgl
gl.attributes
gl.hostUI
gl.inFrame
gl.isWrapped
gl.mark
gl.markFrame
gl.notifier
gl.options
gl.resources
gl.requestCapture
gl.statistics
gl.window
gl.__hasHacksInstalled

My plan is to put only 1 property on the context and make it un-enumerable and put all of these on it.

Does that sound ok?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants