Skip to content

Fix gpu picking instances when instances are disposed #16528

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

Merged
merged 3 commits into from
Apr 25, 2025

Conversation

lockphase
Copy link
Contributor

@lockphase lockphase commented Apr 25, 2025

From: https://forum.babylonjs.com/t/removing-thin-instances-vs-gpupicker/57989/5

Disposing an instance fouls up the gpu picking result. This is due to changes in the order of instances in mesh.instances . Fixed correct mapping of color id of instances to pickable instances by checking against _pickableMeshes instead.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 25, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 25, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 25, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 25, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 25, 2025

Copy link
Contributor

@deltakosh deltakosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job!

@deltakosh deltakosh merged commit a1f5874 into BabylonJS:master Apr 25, 2025
17 checks passed
@lockphase
Copy link
Contributor Author

Its not good enough. :( I opened #16534 to fix the callback and some minor cleanup. Pls review, thanks.

deltakosh pushed a commit that referenced this pull request Apr 30, 2025
The fix in #16528 now correctly throws `Uncaught TypeError: Cannot read
properties of undefined (reading 'r')` when disposing last instance from
a mesh
(https://playground.babylonjs.com/?snapshot=refs/pull/16528/merge#0E9WBX).
This is identical to the thin instance case in forum
(https://forum.babylonjs.com/t/removing-thin-instances-vs-gpupicker/57989).

The correct sequence is for the user to update the picking list after
dispose/matrix buffer. While this repo isn't the primary culprit, its
still annoying when the error crashes user app during dev. This PR adds
a stricter check to the callback and performs some minor cleanup missed
in the previous fix.
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

Successfully merging this pull request may close these issues.

3 participants