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

Add support for eDEFAULT for bitflags (and maybe enums) #225

Open
Jake-Shadle opened this issue Jan 24, 2024 · 0 comments
Open

Add support for eDEFAULT for bitflags (and maybe enums) #225

Jake-Shadle opened this issue Jan 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Jake-Shadle
Copy link
Member

Currently, we #[derive(Default)] for generated bitflags! in physx-sys, which is 0, which might not actually align with what the default is in C++.

Take PxGeometryQueryFlags

https://github.com/NVIDIA-Omniverse/PhysX/blob/85befb639eb736bc8ec7d4a2e9726ec2ab1d0434/physx/include/geometry/PxGeometryQueryFlags.h#L47-L55

Which currently generates

/// Geometry-level query flags.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum PxGeometryQueryFlag {
/// Saves/restores SIMD control word for each query (safer but slower). Omit this if you took care of it yourself in your app.
SimdGuard = 1,
}
bitflags::bitflags! {
/// Flags for [`PxGeometryQueryFlag`]
#[derive(Default)]
#[repr(transparent)]
pub struct PxGeometryQueryFlags: u32 {
const SimdGuard = 1 << 0;
}
}

This will in most cases be harmless, particularly if the default is in fact 0, but for other cases it's either (silently) misleading or could cause crashes/incorrect behavior.

It should be relatively trivial to actually do impl Default for <> for both the enum and the bitflags if the enum in question does in fact have an eDEFAULT variant, otherwise we should leave the default off to force the user to consult the docs/code to make a decision rather than the current behavior.

@Jake-Shadle Jake-Shadle added the bug Something isn't working label Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant