Skip to content

Commit 5fcef5d

Browse files
committed
*: Demote some assert! to debug_assert!
Also removes some assertions that were kind of iffy in cuda_gl. Mostly in a pitiful attempt to micro-optimize debug builds
1 parent c1e78a7 commit 5fcef5d

File tree

5 files changed

+11
-21
lines changed

5 files changed

+11
-21
lines changed

crates/letsplay_av_ffmpeg/src/cuda_gl/safe.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ impl MappedGraphicsResource {
3131
}
3232

3333
pub fn get_mapped_array(&mut self) -> Result<cuda_sys::CUarray, cuda_result::DriverError> {
34-
assert!(
35-
!self.resource.is_null(),
36-
"do not call GraphicsResource::get_mapped_array if no resource is actually registered"
37-
);
38-
3934
let mut array: cuda_sys::CUarray = std::ptr::null_mut();
4035

4136
unsafe {
@@ -50,11 +45,6 @@ impl MappedGraphicsResource {
5045
pub fn get_device_pointer(
5146
&mut self,
5247
) -> Result<cuda_sys::CUdeviceptr, cuda_result::DriverError> {
53-
assert!(
54-
!self.resource.is_null(),
55-
"do not call GraphicsResource::get_mapped_array if no resource is actually registered"
56-
);
57-
5848
let mut array: cuda_sys::CUdeviceptr = 0;
5949
let mut size: usize = 0;
6050

@@ -94,6 +84,8 @@ impl GraphicsResource {
9484

9585
/// Maps this resource.
9686
pub fn map(&mut self) -> Result<MappedGraphicsResource, cuda_result::DriverError> {
87+
assert!(self.is_registered(), "Must register a resource before calling GraphicsResource::map()");
88+
9789
let mut res = MappedGraphicsResource::new(self.resource);
9890
res.map()?;
9991

@@ -106,7 +98,7 @@ impl GraphicsResource {
10698
texture_kind: gl::types::GLuint,
10799
) -> Result<(), cuda_result::DriverError> {
108100
// better to be safe than leak memory? idk.
109-
if !self.resource.is_null() {
101+
if self.is_registered() {
110102
self.unregister()?;
111103
}
112104

@@ -124,10 +116,10 @@ impl GraphicsResource {
124116
}
125117

126118
pub fn unregister(&mut self) -> Result<(), cuda_result::DriverError> {
127-
assert!(
128-
!self.resource.is_null(),
129-
"do not call if no resource is actually registered"
130-
);
119+
// Don't need to unregister if nothing's actually registered
120+
if !self.is_registered() {
121+
return Ok(());
122+
}
131123

132124
unsafe {
133125
cuda_sys::lib()

crates/letsplay_core/src/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::alloc;
44
/// Unlike a [Vec<_>], this can't grow,
55
/// but is just as safe to use, and slightly more predictable.
66
pub fn alloc_boxed_slice<T: Sized>(len: usize) -> Box<[T]> {
7-
assert_ne!(len, 0, "length cannot be 0");
7+
debug_assert_ne!(len, 0, "length cannot be 0");
88
let layout = alloc::Layout::array::<T>(len).expect("?");
99

1010
let ptr = unsafe { alloc::alloc_zeroed(layout) as *mut T };

crates/letsplay_gpu/src/gl_framebuffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl GlFramebuffer {
137137
pub fn read_pixels(&self, buffer: &mut [u32], width: u32, height: u32) {
138138
let _guard = self.bind();
139139

140-
assert_eq!(
140+
debug_assert_eq!(
141141
buffer.len(),
142142
(width * height) as usize,
143143
"Provided buffer cannot hold the framebuffer"

crates/letsplay_gpu/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub mod egl_helpers {
4747
// If it does your video drivers are more than likely broken beyond repair.
4848
unsafe {
4949
let extensions_ptr = QueryString(display, EXTENSIONS as i32);
50-
assert!(!extensions_ptr.is_null());
50+
debug_assert!(!extensions_ptr.is_null());
5151

5252
let extensions_str = std::ffi::CStr::from_ptr(extensions_ptr)
5353
.to_str()

crates/letsplay_retro_frontend/src/frontend/log.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ use tracing::*;
77
/// This recieves log messages from our C++ helper code, and pulls them out into Tracing messages.
88
pub extern "C" fn letsplay_retro_frontend_log(level: LogLevel, buf: *const ffi::c_char) {
99
// SAFETY: The [buf] pointer is null-checked in the C++ helper code, and the helper
10-
// will never call us if the pointer is null.
10+
// will never call into Rust if the pointer happens to be null.
1111
unsafe {
12-
debug_assert!(!buf.is_null(), "This pointer should NEVER be null");
13-
1412
match ffi::CStr::from_ptr(buf).to_str() {
1513
Ok(message) => match level {
1614
LogLevel::Debug => {

0 commit comments

Comments
 (0)