尝试在 Rust 中使用 NiTE 2.2 时出现分段错误,尝试nitereadUserTrackerFrame()
从 NiteCAPI.h 调用时发生分段错误。使用以下命令使用 rust-bindgen 生成绑定。
bindgen Nite.h -o NiTE.rs --whitelist-function nite.* --whitelist-type Nite.* --whitelist-var NITE_.* -- -x c++ -I../OpenNI2.2/Include
并且 OpenNI 绑定是用...生成的
bindgen OpenNI.h --whitelist-type Oni.* --whitelist-function Oni.* --whitelist-function oni.* -o OpenNI.rs -- -x c++
触发分段错误的代码
pub struct nite_UserTracker {
pub m_userTrackerHandle: *mut MaybeUninit<NiteUserTracker>
}
impl nite_UserTracker {
pub fn readFrame(&mut self, pFrame:*mut nite_UserTrackerFrameRef) -> NiteStatus {
let mut pNiteFrame:MaybeUninit<NiteUserTrackerFrame> = MaybeUninit::<NiteUserTrackerFrame>::uninit();
let rc:NiteStatus = unsafe {niteReadUserTrackerFrame((*(self.m_userTrackerHandle)).as_mut_ptr(), pNiteFrame.as_mut_ptr() as *mut *mut NiteUserTrackerFrame)};
unsafe {nite_UserTrackerFrameRef::setReference(&mut (*pFrame), (*(self.m_userTrackerHandle)).as_mut_ptr(), &mut (*pNiteFrame.as_mut_ptr()))}
return rc;
}
}
我相信这是一个与指向pNiteFrame.as_mut_pointer()
我的 gdb 输出的指针相关的错误,如下所示
0x00007ffff76a88b0 in oni::implementation::VideoStream::getDevice() ()
from /home/yashr/Documents/CoolKinectVrThingy/libs/NiTE-Linux-x64-2.2/Samples/Bin/libOpenNI2.so
(gdb) backtrace -full
#0 0x00007ffff76a88b0 in oni::implementation::VideoStream::getDevice() ()
from /home/yashr/Documents/CoolKinectVrThingy/libs/NiTE-Linux-x64-2.2/Samples/Bin/libOpenNI2.so
No symbol table info available.
#1 0x00007ffff7697e61 in oni::implementation::Context::waitForStreams(_OniStream**, int, int*, int) ()
from /home/yashr/Documents/CoolKinectVrThingy/libs/NiTE-Linux-x64-2.2/Samples/Bin/libOpenNI2.so
No symbol table info available.
#2 0x00007ffff7698027 in oni::implementation::Context::readFrame(_OniStream*, OniFrame**) ()
from /home/yashr/Documents/CoolKinectVrThingy/libs/NiTE-Linux-x64-2.2/Samples/Bin/libOpenNI2.so
No symbol table info available.
#3 0x00007ffff79456ba in UserTracker::getNextFrame(NiteUserTrackerFrame**) ()
from /home/yashr/Documents/CoolKinectVrThingy/libs/NiTE-Linux-x64-2.2/Samples/Bin/libNiTE2.so
No symbol table info available.
#4 0x000055555555d803 in CoolKinectVrThingy::NiTE::nite_UserTracker::readFrame
(self=0x7fffffffce50, pFrame=0x7fffffffd2f8) at src/NiTE.rs:2101
pNiteFrame = core::mem::maybe_uninit::MaybeUninit<CoolKinectVrThingy::NiTE::NiteUserTrackerFrame> {uninit: (), value: core::mem::manually_drop::ManuallyDrop<CoolKinectVrThingy::NiTE:--Type <RET> for more, q to quit, c to continue wi--Type <RET> for more, q to quit, c to con--Type <RET> for more, q to quit, c to--Type <RET> for more, q to quit, c to continue without pagi--Type <RET> for more, q to quit, c to continue without paging--Quit