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 'primitive') #2895

Closed
Tirzono opened this issue Jun 19, 2023 · 6 comments
Closed

Cannot read properties of undefined (reading 'primitive') #2895

Tirzono opened this issue Jun 19, 2023 · 6 comments

Comments

@Tirzono
Copy link
Contributor

Tirzono commented Jun 19, 2023

Issue: have two meshes that share the same geometry with a primitive. Remove one mesh and then add the mesh again. You'll then get the error:

Cannot read properties of undefined (reading 'primitive')

Codesandbox: https://codesandbox.io/s/falling-rain-pr3nlj?file=/src/App.js

To reproduce the issue:

  1. Click on "toggle left": left mesh is removed
  2. Click on "toggle left" again: left mesh should be added again

The issue was introduced in 64c1b2f by @CodyJasonBennett

I am not entirely sure if this is a bug. I think it is, because I believe that in vanilla three.js you can use the same geometry for multiple meshes, but let me know if you think otherwise.

@micha2it
Copy link

micha2it commented Jun 20, 2023

I stumbled upon the same issue, issue is gone when downgrading fiber to 8.13.0

@CodyJasonBennett
Copy link
Member

This pattern unfortunately isn't very well supported atm, the work-around being to declare geometry or whatever is attached as a prop to the parent. R3F v8 sees instances 1-1 with their React node counterparts which can only exist at one point in the tree at a time; this relied on broken behavior where instances would hold on to previous nodes' state. I've tried to support this behavior since this is a design issue of R3F (#2294), but it required much larger architectural changes which are in v9. Object3Ds still can only be in one place at a time, but it will permit usage such as this and be limited to three.js hierarchy.

@Tirzono
Copy link
Contributor Author

Tirzono commented Jun 21, 2023

Thanks for explaining. So if I understand it correctly it's probably best to wait for v9 because in v8 it probably won't be supported?

@CodyJasonBennett
Copy link
Member

Maybe, I'd have to cc @drcmda if this is a pattern we can support, but I doubt our ability to use graph structures when neither React or three.js support them. In your case, you can specify geometry as a prop and sidestep any degenerative behavior.

@CodyJasonBennett
Copy link
Member

CodyJasonBennett commented Jun 26, 2023

I'm fixing related crash behavior in #2906 which unblocks this use case. It's not very stable if you then specify props or remount it, so not quite solved, but it's a best effort attempt at clearing things up here.

@Tirzono
Copy link
Contributor Author

Tirzono commented Jun 26, 2023

Thank you for looking into it. I actually realised that a lot of use cases of primitive in my code base can simply be replaced by specifying it as a prop on the parent, so that solved a lot of my problems already. But I appreciate you're looking into this and looking forward to v9 :)

@CodyJasonBennett CodyJasonBennett closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants