Skip to content

Commit

Permalink
fix: Avoid sending garbage to VRCFT (#2669)
Browse files Browse the repository at this point in the history
* fix: Avoid sending garbage to VRCFT

* fix: fix horrible vrcft buffering code

---------

Co-authored-by: Leonhard Saam <[email protected]>
  • Loading branch information
curoviyxru and The-personified-devil authored Jan 27, 2025
1 parent 1b3d1c7 commit f8092a5
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions alvr/server_core/src/tracking/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alvr_common::{anyhow::Result, glam::EulerRot};
use alvr_packets::FaceData;
use alvr_session::FaceTrackingSinkConfig;
use rosc::{OscMessage, OscPacket, OscType};
use std::{f32::consts::PI, mem, net::UdpSocket};
use std::{f32::consts::PI, net::UdpSocket};

const RAD_TO_DEG: f32 = 180.0 / PI;

Expand All @@ -12,7 +12,6 @@ pub struct FaceTrackingSink {
config: FaceTrackingSinkConfig,
socket: UdpSocket,
packet_buffer: Vec<u8>,
packet_cursor: usize,
}

impl FaceTrackingSink {
Expand All @@ -29,7 +28,6 @@ impl FaceTrackingSink {
config,
socket,
packet_buffer: vec![],
packet_cursor: 0,
})
}

Expand All @@ -46,18 +44,10 @@ impl FaceTrackingSink {
}

fn append_packet_vrcft(&mut self, prefix: &[u8; 8], data: &[f32]) {
let new_buffer_len = self.packet_cursor + prefix.len() + data.len() * 4;
if self.packet_buffer.len() < new_buffer_len {
self.packet_buffer.resize(new_buffer_len, 0);
}

self.packet_buffer[self.packet_cursor..][..prefix.len()].copy_from_slice(prefix.as_slice());
self.packet_cursor += prefix.len();
self.packet_buffer.extend(prefix);

for val in data {
self.packet_buffer[self.packet_cursor..][..mem::size_of::<f32>()]
.copy_from_slice(&val.to_le_bytes());
self.packet_cursor += mem::size_of::<f32>();
self.packet_buffer.extend(val.to_le_bytes());
}
}

Expand Down Expand Up @@ -112,7 +102,7 @@ impl FaceTrackingSink {
}
}
FaceTrackingSinkConfig::VrcFaceTracking { .. } => {
self.packet_cursor = 0;
self.packet_buffer.clear();

match face_data.eye_gazes {
[Some(left_quat), Some(right_quat)] => {
Expand Down

0 comments on commit f8092a5

Please sign in to comment.