forge
Explore
Log in

Don't you dare go Hollow

Windows N (no Media Feature Pack) failed to start: Media Foundation DLLs are delay-loaded and the camera is skipped when they are missing

Browse files at this commit

a66fcda6f70dbe3e66af8f405c287e8a07bfd636Ahmet Kaan GümüşParent: 1f8d6c0
  • fix
    • Windows N (no Media Feature Pack) failed to start: Media Foundation DLLs are delay-loaded and the camera is skipped when they are missing
    • harness/imports.sh fails on any import outside the DLLs every Windows has
Show full message
🐛 fix: Windows N (no Media Feature Pack) failed to start: Media Foundation DLLs are delay-loaded and the camera is skipped when they are missing; harness/imports.sh fails on any import outside the DLLs every Windows has
crates/client/build.rsmodified+7 -0
@@ -7,9 +7,16 @@ const COLORS: [&str; 10] = [
7 "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad",7 "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad",
8 ];8 ];
9 const SCALES: [&str; 6] = ["space", "radius", "stroke", "text", "size", "leading"];9 const SCALES: [&str; 6] = ["space", "radius", "stroke", "text", "size", "leading"];
10+const MEDIA_FOUNDATION: [&str; 3] = ["mf.dll", "mfplat.dll", "mfreadwrite.dll"];
10 11
11 fn main() {12 fn main() {
12 println!("cargo::rerun-if-changed={SOURCE}");13 println!("cargo::rerun-if-changed={SOURCE}");
14+ if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
15+ for dll in MEDIA_FOUNDATION {
16+ println!("cargo::rustc-link-arg-bins=/DELAYLOAD:{dll}");
17+ }
18+ println!("cargo::rustc-link-arg-bins=delayimp.lib");
19+ }
13 let tokens: Table = fs::read_to_string(SOURCE)20 let tokens: Table = fs::read_to_string(SOURCE)
14 .expect("read tokens")21 .expect("read tokens")
15 .parse()22 .parse()
crates/client/src/share/camera.rsmodified+18 -0
@@ -57,6 +57,18 @@ impl Drop for Camera {
57 }57 }
58 }58 }
59 59
60+const MEDIA_FOUNDATION: [&str; 3] = ["mf.dll", "mfplat.dll", "mfreadwrite.dll"];
61+
62+fn available() -> bool {
63+ if !cfg!(windows) {
64+ return true;
65+ }
66+ let system = std::env::var("SystemRoot").unwrap_or_else(|_| r"C:\Windows".to_string());
67+ MEDIA_FOUNDATION
68+ .iter()
69+ .all(|dll| std::path::Path::new(&system).join("System32").join(dll).exists())
70+}
71+
60 pub fn open(top: Quality) -> Result<Camera, String> {72 pub fn open(top: Quality) -> Result<Camera, String> {
61 if let Ok(spec) = std::env::var("YUMUSH_TEST_CAMERA") {73 if let Ok(spec) = std::env::var("YUMUSH_TEST_CAMERA") {
62 let (width, height, refresh, frames, generator) = fake::start(&spec);74 let (width, height, refresh, frames, generator) = fake::start(&spec);
@@ -73,6 +85,9 @@ pub fn open(top: Quality) -> Result<Camera, String> {
73 _fake: Some(generator),85 _fake: Some(generator),
74 });86 });
75 }87 }
88+ if !available() {
89+ return Err("Camera needs the Media Feature Pack".to_string());
90+ }
76 let (negotiated_tx, negotiated_rx) = sync_channel::<Result<Negotiated, String>>(1);91 let (negotiated_tx, negotiated_rx) = sync_channel::<Result<Negotiated, String>>(1);
77 let (frames_tx, frames_rx) = sync_channel(FRAME_QUEUE);92 let (frames_tx, frames_rx) = sync_channel(FRAME_QUEUE);
78 let stop = Arc::new(AtomicBool::new(false));93 let stop = Arc::new(AtomicBool::new(false));
@@ -123,6 +138,9 @@ pub fn list() -> Vec<Mode> {
123 .into_iter()138 .into_iter()
124 .collect();139 .collect();
125 }140 }
141+ if !available() {
142+ return Vec::new();
143+ }
126 let any = RequestedFormat::new::<RgbFormat>(RequestedFormatType::None);144 let any = RequestedFormat::new::<RgbFormat>(RequestedFormatType::None);
127 Device::new(CameraIndex::Index(0), any)145 Device::new(CameraIndex::Index(0), any)
128 .and_then(|mut camera| camera.compatible_camera_formats())146 .and_then(|mut camera| camera.compatible_camera_formats())
harness/imports.shadded+12 -0
@@ -0,0 +1,12 @@
1+#!/usr/bin/env bash
2+set -euo pipefail
3+exe="${1:-$(dirname "$0")/../target/windows/yumush.exe}"
4+core="advapi32 api-ms-win-core-synch-l1-2-0 api-ms-win-core-winrt-error-l1-1-0 api-ms-win-core-winrt-l1-1-0
5+api-ms-win-shcore-scaling-l1-1-1 bcrypt bcryptprimitives combase comctl32 coremessaging crypt32 d3d11 dcomp
6+dwmapi dwrite dxgi gdi32 gdiplus icuuc imm32 kernel32 mmdevapi msimg32 ntdll ole32 oleaut32 pdh powrprof
7+propsys psapi shell32 uiautomationcore user32 userenv winmm ws2_32"
8+extra=$(objdump -p "$exe" | sed -n 's/.*DLL Name: //p' | tr A-Z a-z | sed 's/\.dll$//' | sort -u |
9+ grep -vxF -f <(tr ' ' '\n' <<<"$core" | grep .) || true)
10+[ -z "$extra" ] && { echo "imports ok"; exit 0; }
11+echo "not on every Windows, delay-load and guard it: $extra"
12+exit 1