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

Invalid LocalState of primitives after resuse #3143

Open
Inuniku opened this issue Jan 7, 2024 · 0 comments
Open

Invalid LocalState of primitives after resuse #3143

Inuniku opened this issue Jan 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Inuniku
Copy link
Contributor

Inuniku commented Jan 7, 2024

Please see #3142 for an attempted partial fix. Might be related to #3125.

In my concrete case I used a list of loaded glb-files. After changing the list, sometimes the whole glb-scene wouldn't show up anymore.

This is because changing the list while using the same primitive (as useGLTF gives the same cached scene) the isPrimitive tag got cleared and that caused the whole gltf scene to dispose/unmount.

I created a test to reproduce my case:

// Initialize a list of primitives
await act(async () =>
  root.render(
    <group>
      <primitive key={'a'} object={primitive1} name="p1" dispose={null} />
    </group>,
  ),
)

expect((primitive1 as any).__r3f?.type).toBe('primitive')

// New list of primitives while reusing primitive object
await act(async () =>
  root.render(
    <group>
      <primitive key={'b'} object={primitive1} name="p1" dispose={null} />
      <primitive key={'c'} object={primitive2} name="p2" dispose={null} />
    </group>,
  ),
)

expect((primitive1 as any).__r3f?.type).toBe('primitive') // fails, is '' instead
expect((primitive2 as any).__r3f?.type).toBe('primitive')

I created a test where a similar bug happens, which has not yet been addressed by me. This test still fails:

await act(async () =>
  root.render(
    <group>
      <primitive object={primitive1} dispose={null} />
    </group>,
  ),
)
expect((primitive1 as any).__r3f?.type).toBe('primitive')
await act(async () =>
  root.render(
    <group>
      <primitive object={primitive2} dispose={null} />
      <primitive object={primitive1} dispose={null} />
    </group>,
  ),
)
expect((primitive1 as any).__r3f?.type).toBe('primitive') 
expect((primitive2 as any).__r3f?.type).toBe('primitive') 
@CodyJasonBennett CodyJasonBennett added the bug Something isn't working label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants