Skip to content

specialized_mesh_pipeline example panics when hovering over mesh #15891

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

Closed
rparrett opened this issue Oct 13, 2024 · 4 comments · Fixed by #15899
Closed

specialized_mesh_pipeline example panics when hovering over mesh #15891

rparrett opened this issue Oct 13, 2024 · 4 comments · Fixed by #15899
Labels
A-Picking Pointing at and selecting objects of all sorts A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior P-Crash A sudden unexpected crash S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Milestone

Comments

@rparrett
Copy link
Contributor

rparrett commented Oct 13, 2024

Bevy version

main
bisected to #15800.

Relevant system information

SystemInfo { os: "MacOS 14.5 ", kernel: "23.5.0", cpu: "Apple M1 Max", core_count: "10", memory: "64.0 GiB" }
AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

What you did

  • cargo run --example specialized_mesh_pipeline
  • hover over over the triangles

What went wrong

thread 'Compute Task Pool (3)' panicked at crates/bevy_picking/src/mesh_picking/ray_cast/intersections.rs:145:29:
index out of bounds: the len is 3 but the index is 3
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_picking::mesh_picking::update_hits`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
@rparrett rparrett added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 13, 2024
@rparrett rparrett changed the title ` specialized_mesh_pipeline example panics when hovering over mesh Oct 13, 2024
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen A-Picking Pointing at and selecting objects of all sorts and removed S-Needs-Triage This issue needs to be labelled labels Oct 14, 2024
@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Oct 14, 2024
@alice-i-cecile alice-i-cecile added the P-Crash A sudden unexpected crash label Oct 14, 2024
@alice-i-cecile
Copy link
Member

I'm pretty sure something is malformed in the mesh. This looks like the exact issue spotted by @tbillington and called out as not a problem in #15800 (comment) by @Jondolf.

@rparrett
Copy link
Contributor Author

rparrett commented Oct 14, 2024

It looks like it is because the mesh doesn't have normals. Don't feel like we should be packing there, but it seems like there's a pretty nasty perf hit to write non-packing code based on the discussion linked above.

@Jondolf
Copy link
Contributor

Jondolf commented Oct 14, 2024

The line the panic is referring to is indexing the third vertex position for a triangle, not indexing a normal. The code does check if Mesh::ATTRIBUTE_NORMAL exists at all, and should work if it doesn't. I believe normals should only be an issue if there are less normals than there are vertices, which is considered malformed by Bevy anyway.

The panic happens because the example defines the mesh's indices as [0, 1, 2, 0, 2, 3]. Index 3 points to nothing since the mesh only has three vertices. Not sure why it's set up like that or how it's even meant to work.

@BenjaminBrienen BenjaminBrienen added the S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! label Oct 14, 2024
@rparrett
Copy link
Contributor Author

Cool, you're right, thanks. Opened a tiny PR to fix.

github-merge-queue bot pushed a commit that referenced this issue Oct 15, 2024
# Objective

Fixes #15891

## Solution

Just remove the invalid triangle. I'm assuming that line of code was
originally copied from one that was drawing a quad.

## Testing

- `cargo run --example specialized_mesh_pipeline`
- hover over over the triangles

Tested on macos
github-merge-queue bot pushed a commit that referenced this issue Mar 10, 2025
_Note from BD103: this PR was adopted from #16148. The majority of this
PR's description is copied from the original._

# Objective

Adds tests to cover various mesh picking cases and removes sources of
panics.

It should prevent users being able to trigger panics in `bevy_picking`
code via bad mesh data such as #15891, and is a follow up to my comments
in [#15800
(review)](#15800 (review)).

This is motivated by #15979

## Testing

Adds 8 new tests to cover `ray_mesh_intersection` code.

## Changes from original PR

I reverted the changes to the benchmarks, since that was the largest
factor blocking it merging. I'll open a follow-up issue so that those
benchmark changes can be implemented.

---------

Co-authored-by: Trent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Picking Pointing at and selecting objects of all sorts A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior P-Crash A sudden unexpected crash S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants