React-three-fiber: Adding a second instance of Canvas increases render loop speed

Created on 21 Jun 2019  路  8Comments  路  Source: pmndrs/react-three-fiber

Hey all,

Thanks creating such a useful library.

I'm noticing some odd behavior when instantiating multiple Canvas objects. Any updates happening in useRender are performed twice as fast when the second canvas is added. Possibly the useRender callbacks are being called once for each renderer regardless of the renderer they should be attached to?

https://codesandbox.io/embed/react-three-fiber-multi-render-test-m3h2q

I've created a codesandbox reproducing the issue in it's simplest form. After 5 seconds a second canvas is added and the first cube's rotation speed increases for some reason.

As far as I can tell this issue started somewhere around v2.0.11, seemed to be working alright before that.

Thanks for all the help

Dex

bug

Most helpful comment

that doesn't make any sense, so weird - looks like for some reason it calls the useRender twice. 馃く will have to investigate a bit ...

All 8 comments

react-three-fiber-render-speed-bug
Gif for quick reference

that doesn't make any sense, so weird - looks like for some reason it calls the useRender twice. 馃く will have to investigate a bit ...

Clearing the subscribers when creating the initial canvas state seems to fix the issue. I'm not familiar enough with the code to know if that's a good idea but happy to make a PR if it seems like a reasonable approach.

https://github.com/DexterShepherd/react-three-fiber/commit/68ed44b1050cb71337b4c697560cb3d8c04c0634#diff-acdd4dfc96db39da09ff08b9a2fdc0e2

sure, go ahead! :)

tho isn't subscribers:[] part of defaultRef already?

I don't think the object spread operator performs a deep clone, so all objects that spread defaultRef would point to the same copy of subscribers.

Screen Shot 2019-06-22 at 10 37 40 AM

oh my ... you're right, that was a terrible oversight. the problem goes even deeper now, because it mutates that defaultRef, camera, scene and all. It's a wonder it's kind of working.

It should be fixed, but i had to fix the other parts as well (scene, cam, raycaster, etc) which all were equally affected, not just subscriber.

Awesome thanks for getting to this so quickly :)

I was wondering why my game sped up after a hot reload, I wonder if this is why, I'll try bumping versions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Darkensses picture Darkensses  路  6Comments

ghost picture ghost  路  6Comments

AndrewRayCode picture AndrewRayCode  路  5Comments

gtolarc picture gtolarc  路  4Comments

jamestubman picture jamestubman  路  6Comments