Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'dispose') - GridHelper #721

Closed
5 tasks done
whitespacecode opened this issue Jun 5, 2024 · 6 comments · Fixed by #764
Closed
5 tasks done

Cannot read properties of undefined (reading 'dispose') - GridHelper #721

whitespacecode opened this issue Jun 5, 2024 · 6 comments · Fixed by #764
Assignees
Labels
p2-edge-case Bug, but has a workaround or limited in scope (priority)

Comments

@whitespacecode
Copy link

whitespacecode commented Jun 5, 2024

Describe the bug

When i try to show/hide the GridHelper i get a TypeError. The code still works.
I tried it on an older tresjs version and no typeError happend.

<TresGridHelper v-if="gridHelper.visible" :args="[10, 100, 0xff0000]" />
image

Not sure if that is also the case for other components.

Reproduction

https://stackblitz.com/edit/tresjs-basic-hfgtuj

Steps to reproduce

Use the reproduction, click on the button 'Toggle Grid' and check the console logs.

System Info

System:
    OS: macOS 14.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 90.73 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v18.18.0/bin/yarn
    npm: 10.6.0 - ~/Code/Modulab/node_modules/.bin/npm
  Browsers:
    Chrome: 125.0.6422.142
  npmPackages:
    @tresjs/cientos: ^3.9 => 3.9.0
    @tresjs/core: ^4.0.2 => 4.0.2
    vite: ^5.2.10 => 5.2.10

Used Package Manager

npm

Code of Conduct

@garrlker garrlker added the p2-edge-case Bug, but has a workaround or limited in scope (priority) label Jun 7, 2024
@garrlker garrlker self-assigned this Jun 7, 2024
@garrlker
Copy link
Collaborator

garrlker commented Jun 7, 2024

Looks like we're calling .dispose() twice when this is removed from the scene. Easy fix, though it's interesting how this bug got in

@alvarosabu
Copy link
Member

@andretchen0 is this solved by the disposal refactor?

@andretchen0
Copy link
Contributor

@alvarosabu

is this solved by the disposal refactor?

Most likely. I will make a test from the reproduction and add it to the nodeOps tests.

@andretchen0
Copy link
Contributor

Following up, this is indeed a problem with Tres nodeOps (Vue's RendererOptions) remove.

This test against main currently fails:

  it('disposes a GridHelper', () => {
    const gridHelper = nodeOps.createElement('TresGridHelper', undefined, undefined, {})
    expect(() => nodeOps.remove(gridHelper)).not.toThrow()
  })

@andretchen0
Copy link
Contributor

andretchen0 commented Jul 4, 2024

@garrlker

I see you're assigned here.

Fwiw, the issue is fixed in a soon-to-be submitted PR dealing with primitive/disposal.

When I submit, I'll mark that PR as closing this issue, if that's ok.

@andretchen0
Copy link
Contributor

andretchen0 commented Jul 8, 2024

Just for future reference, it is interesting:

Looks like we're calling .dispose() twice when this is removed from the scene. Easy fix, though it's interesting how this bug got in

The bug stems from these 2 competing disposals:

  • THREE creates the GridHelper along with its material and geometry. When its dispose method is called, the THREE code tries to this.material.dispose(). It assumes that this.material exists – which is a perfectly valid assumption, since THREE put it there.
  • Tres disposes from the bottom up. Children are disposed and detached before parents.

By the time Tres calls dispose on the GridHelper, Tres has already disposed and removed its material and geometry.

That makes THREE's perfectly valid assumption wrong, unfortunately. THREE tries to do this.material.dispose(), which throws because Tres had removed this.materal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-edge-case Bug, but has a workaround or limited in scope (priority)
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants