Search code examples
three.js

How do I stop requestAnimationFrame


I need to remove a canvas and build a new one. I'm having a problem where I don't know how to stop/interrupt the Three.js or webGL update process. I can stop it if I force a javascript error (but that's really stupid).

Does anyone know how to stop the process so that I don't start to pile processes that aren't doing anything useful or conflicting with the new ones?


Solution

  • let id;
    
    function animate() {
    
        id = requestAnimationFrame( animate );
    
        renderer.render( scene, camera );
    
    }
    

    To cancel:

    cancelAnimationFrame( id );
    

    three.js r.55