mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Fix overflow in RenderLayers::iter_layers
(#14264)
# Objective - Fixes overflow when calling `RenderLayers::iter_layers` on layers of the form `k * 64 - 1` - Causes a panic in debug mode, and an infinite iterator in release mode ## Solution - Use `u64::checked_shr` instead of `>>=` ## Testing - Added a test case for this: `render_layer_iter_no_overflow`
This commit is contained in:
parent
ab255aefc6
commit
a79df7b124
1 changed files with 7 additions and 1 deletions
|
@ -162,7 +162,7 @@ impl RenderLayers {
|
|||
return None;
|
||||
}
|
||||
let next = buffer.trailing_zeros() + 1;
|
||||
buffer >>= next;
|
||||
buffer = buffer.checked_shr(next).unwrap_or(0);
|
||||
layer += next as usize;
|
||||
Some(layer - 1)
|
||||
})
|
||||
|
@ -359,4 +359,10 @@ mod rendering_mask_tests {
|
|||
let layers = layers.without(77);
|
||||
assert!(layers.0.len() == 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_layer_iter_no_overflow() {
|
||||
let layers = RenderLayers::from_layers(&[63]);
|
||||
layers.iter().count();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue