jeromeetienne / threejs-inspector

chrome devtool extension to debug three.js
https://chrome.google.com/webstore/detail/threejs-inspector/dnhjfclbfhcbcdfpjaeacomhbdfjbebi
200 stars 45 forks source link

requestAnimationFrame returns undefined #21

Open fritx opened 7 years ago

fritx commented 7 years ago

Hi, the inspector is awesome and useful, but I met a problem:

After launching inspector, requestAnimationFrame returns undefined instead of an id number which we can call with cancelAnimationFrame.

I looked through the source code, and found the cause: https://github.com/jeromeetienne/threejs-inspector/blob/df3ef41ad22d3be2fd6be91ac23c425f1b64f4a9/src/vendor/raf-throttler.js#L14-L32

requestAnimationFrame   = function(callback){
    if( _this.fps === -1 ){
        originalFct(function(timestamp){
            onAnimationFrame(callback, timestamp)               
        })          
    }else if( _this.fps > 0 ){
        setTimeout(function(){
            onAnimationFrame(callback, performance.now())
        }, 1000 / _this.fps)
    }else if( _this.fps === 0 ){
        var intervalId = setInterval(function(){
            if( _this.fps === 0 )   return
            clearInterval(intervalId)
            onAnimationFrame(callback, performance.now())   
        }, 100)
    }else {
        console.assert(false)
    }
}

We should just return the id number while we are rewriting the method.