brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
822 stars 105 forks source link

render infinitely - scene, engine hooks #212

Closed slash9494 closed 2 years ago

slash9494 commented 2 years ago

i found infinite render loop when i used hooks ( useScene, useEngine) in components (such as light, model)

but i have not been aware of it if i don't use dev tools like console and it seems to be alright

is it normal situation ?

brianzinn commented 2 years ago

can you share a repro - perhaps on codepen? I have never seen that before. sounds like you are saying that when you use devtools that it stops.... the render loop is running on the Engine automatically. Otherwise if you can share code here.

slash9494 commented 2 years ago

i find that my fps update state have made it render infinitely 😅 i think this code setFps(engine?.getFps() || 0 ) could generate useEngine

brianzinn commented 2 years ago

thanks for sharing the solution. setFps looks like a useState - that will cause a React render - not good performance to call every frame - poor performance. Better to do that outside of React - on the canvas or vanilla js. Glad you solved it 😄