-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
NodeOps shares scene
across multipleTresCanvas
s
#560
Comments
scene
across multipleTresCanvas
'sscene
across multipleTresCanvas
's
scene
across multipleTresCanvas
'sscene
across multipleTresCanvas
s
scene
across multipleTresCanvas
sscene
across multipleTresCanvas
s
Brilliant catch @andretchen0 thanks for the detailed reproduction!
This was the original purpose, but it seems we didn't implement it correctly, I think your idea about refactoring The weirdest thing is that I managed to reproduce the behavior only in stackblitz, in the playground we have a demo for multiple canvases, and it is not happening @andretchen0. I'm using a Screen.Recording.2024-03-06.at.19.53.50.mov |
I spent more time reproducing it and the only reason why was working on the playground it was because it was wrapped with |
No worries. Bugs happen. In the hope that it's helpful to mention: looking at the code, I have a hunch that some of the Vue SFC model has rubbed off on the way some plain ES modules were written. (It happens to me, so I'm assuming others, too.) Like the code in src/core/renderer.ts:
If one has the Vue But ES modules are something like singletons. They're only evaluated the first time they're imported. In this case, it means all Mostly that wasn't a problem because mostly the Vue renderer (nodeOps) functions just work on the arguments passed to them ... just not in the case of |
Bug
NodeOps accidentally shares
scene
across multipleTresCanvas
s.See the StackBlitz reproduction for details.
Problem
NodeOps's
let scene
is set whenever a newScene
is added to anyTresCanvas
– i.e., the variable points to the lastScene
added to aTresCanvas
. If elements from anotherTresCanvas
readscene
in nodeOps, the code expects that they will find theirScene
, but they do not.Solution?
Solution A
We could refactor nodeOps as
(context: TresContext) => NodeOps
.Every new instance of
TresCanvas
could create a new nodeOps instance which contains a uniqueTresContext
(i.e., with the appropriateScene
) within its scope.Solution B
Otherwise, we could simply recurse up the parent chain until we reach a
Scene
or run out of parents.Reproduction
https://stackblitz.com/edit/tresjs-basic-e6uzmm?file=src%2FApp.vue
System Info
Used Package Manager
npm
Code of Conduct
The text was updated successfully, but these errors were encountered: