Skip to content

Commit

Permalink
Fix a crash in a test on Windows
Browse files Browse the repository at this point in the history
Probably caused by a wrong memory alignment
  • Loading branch information
Luni-4 committed Aug 24, 2022
1 parent fc2e0cd commit 4b7aeaa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions data/Cargo.toml
Expand Up @@ -10,8 +10,8 @@ readme = "README.md"
edition = "2021"

[dependencies]
byte-slice-cast = "1.0.0"
bytes = "1.0.0"
byte-slice-cast = "1.2.1"
bytes = "1.2.1"
thiserror = "1.0"
num-rational = "0.4.0"
num-traits = "0.2.8"
Expand Down
10 changes: 2 additions & 8 deletions data/src/frame.rs
@@ -1,6 +1,5 @@
#![allow(dead_code, unused_variables)]

use std::alloc::{alloc, Layout};
use std::convert::From;
use std::fmt;
use std::ptr::copy_nonoverlapping;
Expand Down Expand Up @@ -388,9 +387,7 @@ impl DefaultFrameBuffer {
match *kind {
MediaKind::Video(ref video) => {
let size = video.size(ALIGNMENT);
let data = unsafe { alloc(Layout::from_size_align(size, ALIGNMENT).unwrap()) };
//let data = unsafe { Heap.alloc_zeroed(Layout::from_size_align(size, ALIGNMENT)) };
let buf = BytesMut::from(unsafe { &Vec::from_raw_parts(data, size, size)[..] });
let buf = BytesMut::with_capacity(size);
let mut buffer = DefaultFrameBuffer {
buf,
planes: Vec::with_capacity(video.format.get_num_comp()),
Expand All @@ -409,8 +406,7 @@ impl DefaultFrameBuffer {
}
MediaKind::Audio(ref audio) => {
let size = audio.size(ALIGNMENT);
let data = unsafe { alloc(Layout::from_size_align(size, ALIGNMENT).unwrap()) };
let buf = BytesMut::from(unsafe { &Vec::from_raw_parts(data, size, size)[..] });
let buf = BytesMut::with_capacity(size);
let mut buffer = DefaultFrameBuffer {
buf,
planes: if audio.format.planar {
Expand Down Expand Up @@ -616,8 +612,6 @@ mod test {

#[test]
#[should_panic]
// FIXME: On Windows this test does not work
#[cfg(target_os = "linux")]
fn test_frame_copy_from_slice() {
let yuv420: Formaton = *YUV420;
let fm = Arc::new(yuv420);
Expand Down

0 comments on commit 4b7aeaa

Please sign in to comment.