[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Handling context lost in WebGL

On Wed, Oct 12, 2011 at 7:33 PM, Mark Callow <callow_mark@hicorp.co.jp> wrote:


function init() {
  canvas.removeEventListener(‘mousemove’, mouseMoveHandler, false);
  var mouseUniformLocation = gl.getUniformLocation(program, “uMouse”);
  function mouseMoveHandler(event) {
    gl.uniform2f(mouseIniformLocation, event.x, event.y);

  canvas.addEventListener(‘mousemove’, mouseMoveHandler, false);

do you really need the first line?

Yes.  I fixed a typo above (and on the wiki). Maybe that makes it clearer?

There were 2 issues

1) init is called more than once (at the beginning and each time the context is restored).  

That means a new mouseUniformLocation is created each time.  If you made mouseUniformLocation a global instead of a local it would work for example. 

2) when you use an anonymous function as an eventListener there is no way to remove it since you need to pass it to removeEventListener


Since the handler is no longer an anonymous function, it should use the current value of mouseUniformLocation when called.

I think this is a very useful document. Thanks for preparing it.



On 13/10/2011 10:25, Gregg Tavares (wrk) wrote:
I just got through updating all the demos on the Khronos WebGL SDK to handle context lost

I wrote up some of the issues I ran into and their solutions and put them on the WebGL Wiki here

I hope that's useful.