sinisterchipmunk / jax

Framework for creating rich WebGL-enabled applications using JavaScript and Ruby
http://jaxgl.com
MIT License
96 stars 16 forks source link

Can't create a Jax context without a renderer #70

Closed sinisterchipmunk closed 11 years ago

sinisterchipmunk commented 11 years ago

It should be possible to explicitly create a context without a renderer, and even attach it to a non-canvas element. The following should work:

c = new Jax.Context({renderers: [], canvas: document.body});

But instead it fails with:

ReferenceError: renderer is not defined

Interesting to note, if you follow the stack trace, the renderer reference is actually a bug in itself: inside of Jax.Renderer.attemptThese, where Renderer is a string instead of a function, the reference to renderer should be Renderer. However, even if this code worked, attemptThese would ultimately produce an error message complaining that no renderer could be instantiated.

We want to keep the existing error in the event that the specified renderers could not be loaded. So, the answer is to check the length of the requested renderer array one step back, in Jax.Context, and specifically skip renderer initialization if the array is empty.

Something to test: the above code should work just like any other Jax context, except that no rendering should be produce. For example, it should still register event listeners, fire controller methods, and execute views.

sinisterchipmunk commented 11 years ago

FYI, this appears to work (from the console at least) as a workaround until this issue is fixed:

c = new Jax.Context({renderers: []}); // note we leave canvas out
c.canvas = document.body;
c.setupInputDevices();
c.redirectTo("controller/path");

This approach worked with controller methods and events; I did not test views.