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

examples: Replace one more unsafe transmute() with trivial ptr::cast() #351

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/compute/compute-argument-buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn main() {
command_buffer.commit();
command_buffer.wait_until_completed();

let sum = unsafe { sum.contents().cast::<u32>().read() };
let sum = unsafe { *sum.contents().cast::<u32>() };
assert_eq!(465, sum);
});
}
2 changes: 1 addition & 1 deletion examples/compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn main() {
let mut gpu_end = 0;
device.sample_timestamps(&mut cpu_end, &mut gpu_end);

let sum = unsafe { sum.contents().cast::<u32>().read() };
let sum = unsafe { *sum.contents().cast::<u32>() };
println!("Compute shader sum: {}", sum);

assert_eq!(num_elements, sum);
Expand Down
6 changes: 2 additions & 4 deletions examples/raytracing/renderer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
collections::BTreeMap,
mem::transmute,
ops::Index,
sync::{Arc, Condvar, Mutex},
};
Expand Down Expand Up @@ -451,10 +450,9 @@ impl Renderer {
command_encoder.end_encoding();
command_buffer.commit();
command_buffer.wait_until_completed();
let compacted_size: *const u32 = unsafe { transmute(compacted_size_buffer.contents()) };
let compacted_size = unsafe { *compacted_size } as NSUInteger;
let compacted_size = unsafe { *compacted_size_buffer.contents().cast::<u32>() };
let compacted_acceleration_structure =
device.new_acceleration_structure_with_size(compacted_size);
device.new_acceleration_structure_with_size(compacted_size as NSUInteger);
let command_buffer = queue.new_command_buffer();
let command_encoder = command_buffer.new_acceleration_structure_command_encoder();
command_encoder.copy_and_compact_acceleration_structure(
Expand Down