Skip to content

Commit ebc2307

Browse files
committed
Fix the memomry access voilation in minifb example
1 parent 3213bc2 commit ebc2307

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/minifb-demo/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use minifb::{Key, KeyRepeat, Window, WindowOptions};
2+
use plotters::prelude::*;
23
use plotters_bitmap::bitmap_pixel::BGRXPixel;
34
use plotters_bitmap::BitMapBackend;
4-
use plotters::prelude::*;
55
use std::collections::VecDeque;
66
use std::error::Error;
77
use std::time::SystemTime;
@@ -134,7 +134,8 @@ fn main() -> Result<(), Box<dyn Error>> {
134134
break;
135135
}
136136
}
137-
window.update_with_buffer(unsafe { std::mem::transmute(&buf[..]) })?;
137+
let buf = unsafe { std::slice::from_raw_parts(&buf[0] as *const _ as *const _, H * W) };
138+
window.update_with_buffer(buf)?;
138139
last_flushed = epoch;
139140
}
140141

0 commit comments

Comments
 (0)