Search code examples
kineticjs

kineticjs exception on stage.destroyChildren


When I am cleaning up my stage I call

stage.destroyChildren();

When I have done this in the past it works fine. for a new project I am calling it and I get the following exception:

'null' is not an object (evaluating 'f.getCanvas')

f is not one of my variables.

The only thing I can think of at the moment is that the cleanup might be being called when an object is being dragged.


Solution

  • I have fixed it by putting it in a setTimeout

    setTimeout(function(){function_that_calls_destroyChildren();},50);
    

    this solves my problem. I think it does have to do with a race condition with the drag.