Game starts to lag after a few steps

So i’m playing around with this game and i’ve noticed it runs smooth for the first 5 seconds or so then starts to lag what is causing this something in one of the loops?

wonder-3d.hol.es/ADz(1)/114

Solve errors into console

They don’t cause the lag and get resolved later on anyway

Sorry to say, but your code is a mess and hard to get a grasp on, but from what I gathered, you’re using two separate calls to requestAnimationFrame “per frame”, which effectively slows down rendering by 50%. It seems to me that the _RAF() function doesn’t really do much. Try to get rid of that and see if that helps.

Apart from that, it does seem like you’re updating GL states manually quite a bit which may conflict with things that Three is trying to do, but thats just a guess.

there are two requestAnimationFrame one is for the game one is for the mouse effect for the colors etc which is in a separate canvas for the game the only call to requestAnimationFrame is within _RAF() even if i remove the canvas and the mouse effect it still lags

Thats not how you should be using requestAnimationFrame. Use one requestAnimationFrame that calls itself, not two in two separate loops. It doesn’t work that way. You’ll effectively slice your framerate in half.

the lag still happens when i remove the second canvas and code that has the mouse effects in it leave one requestAnimationFrame

Remember what is new was added which made lags. Or compare old version and new version your engine.