Skip to content

NodeOps shares scene across multipleTresCanvass #560

Closed
@andretchen0

Description

Bug

NodeOps accidentally shares scene across multiple TresCanvass.

See the StackBlitz reproduction for details.

Problem

NodeOps's let scene is set whenever a new Scene is added to any TresCanvas – i.e., the variable points to the last Scene added to a TresCanvas. If elements from another TresCanvas read scene in nodeOps, the code expects that they will find their Scene, 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 unique TresContext (i.e., with the appropriate Scene) 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

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.14.0 - /usr/local/bin/pnpm
  npmPackages:
    @tresjs/cientos: ^3.5.1 => 3.5.1 
    @tresjs/core: ^3.4.1 => 3.4.1 
    @tresjs/eslint-config-vue: ^0.2.1 => 0.2.1 
    vite: ^4.5.0 => 4.5.0

Used Package Manager

npm

Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    • Status

      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions