Skip to content

Commit 606b6db

Browse files
committed
Fix mesh picking panic with render world only usages
1 parent 3d8edf0 commit 606b6db

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

crates/bevy_picking/src/mesh_picking/ray_cast/intersections.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bevy_math::{bounding::Aabb3d, Affine3A, Dir3, Ray3d, Vec2, Vec3, Vec3A};
2-
use bevy_mesh::{Indices, Mesh, PrimitiveTopology, VertexAttributeValues};
2+
use bevy_mesh::{Indices, Mesh, MeshExtractableData, PrimitiveTopology, VertexAttributeValues};
33
use bevy_reflect::Reflect;
44

55
use super::Backfaces;
@@ -37,7 +37,7 @@ pub struct RayTriangleHit {
3737

3838
/// Casts a ray on a mesh, and returns the intersection.
3939
pub(super) fn ray_intersection_over_mesh(
40-
mesh: &Mesh,
40+
mesh: &MeshExtractableData,
4141
transform: &Affine3A,
4242
ray: Ray3d,
4343
cull: Backfaces,

crates/bevy_picking/src/mesh_picking/ray_cast/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1717
use intersections::*;
1818
pub use intersections::{ray_aabb_intersection_3d, ray_mesh_intersection, RayMeshHit};
1919

20-
use bevy_asset::{Assets, Handle};
20+
use bevy_asset::{Assets, ExtractableAsset, Handle};
2121
use bevy_ecs::{prelude::*, system::lifetimeless::Read, system::SystemParam};
2222
use bevy_math::FloatOrd;
2323
use bevy_transform::components::GlobalTransform;
@@ -282,6 +282,10 @@ impl<'w, 's> MeshRayCast<'w, 's> {
282282
return;
283283
};
284284

285+
let Ok(data) = mesh.extractable_data_ref() else {
286+
return;
287+
};
288+
285289
// Backfaces of 2d meshes are never culled, unlike 3d meshes.
286290
let backfaces = match (has_backfaces, mesh2d.is_some()) {
287291
(false, false) => Backfaces::Cull,
@@ -291,7 +295,7 @@ impl<'w, 's> MeshRayCast<'w, 's> {
291295
// Perform the actual ray cast.
292296
let _ray_cast_guard = ray_cast_guard.enter();
293297
let transform = transform.affine();
294-
let intersection = ray_intersection_over_mesh(mesh, &transform, ray, backfaces);
298+
let intersection = ray_intersection_over_mesh(data, &transform, ray, backfaces);
295299

296300
if let Some(intersection) = intersection {
297301
let distance = FloatOrd(intersection.distance);

0 commit comments

Comments
 (0)