• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Xevion / Pac-Man / 16885975515

11 Aug 2025 04:25PM UTC coverage: 49.164% (+0.04%) from 49.127%
16885975515

push

github

Xevion
fix(emscripten): string pointer casting, fixup AssetError handling

0 of 4 new or added lines in 2 files covered. (0.0%)

647 of 1316 relevant lines covered (49.16%)

364.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/platform/emscripten.rs
1
//! Emscripten platform implementation.
2

3
use std::borrow::Cow;
4
use std::time::Duration;
5

6
use crate::asset::{Asset, AssetError};
7
use crate::platform::{Platform, PlatformError};
8

9
/// Emscripten platform implementation.
10
pub struct EmscriptenPlatform;
11

12
impl Platform for EmscriptenPlatform {
13
    fn sleep(&self, duration: Duration) {
×
14
        unsafe {
×
15
            emscripten_sleep(duration.as_millis() as u32);
×
16
        }
×
17
    }
×
18

19
    fn get_time(&self) -> f64 {
×
20
        unsafe { emscripten_get_now() }
×
21
    }
×
22

23
    fn init_console(&self) -> Result<(), PlatformError> {
×
24
        Ok(()) // No-op for Emscripten
×
25
    }
×
26

27
    fn get_canvas_size(&self) -> Option<(u32, u32)> {
×
28
        Some(unsafe { get_canvas_size() })
×
29
    }
×
30

31
    fn get_asset_bytes(&self, asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
×
32
        use sdl2::rwops::RWops;
33
        use std::io::Read;
34

35
        let path = format!("assets/game/{}", asset.path());
×
36
        let mut rwops = RWops::from_file(&path, "rb").map_err(|_| AssetError::NotFound(asset.path().to_string()))?;
×
37

38
        let len = rwops.len().ok_or_else(|| AssetError::NotFound(asset.path().to_string()))?;
×
39

40
        let mut buf = vec![0u8; len];
×
41
        rwops
×
42
            .read_exact(&mut buf)
×
NEW
43
            .map_err(|e| AssetError::Io(std::io::Error::other(e)))?;
×
44

45
        Ok(Cow::Owned(buf))
×
46
    }
×
47
}
48

49
// Emscripten FFI functions
50
extern "C" {
51
    fn emscripten_get_now() -> f64;
52
    fn emscripten_sleep(ms: u32);
53
    fn emscripten_get_element_css_size(target: *const u8, width: *mut f64, height: *mut f64) -> i32;
54
}
55

56
unsafe fn get_canvas_size() -> (u32, u32) {
×
57
    let mut width = 0.0;
×
58
    let mut height = 0.0;
×
NEW
59
    emscripten_get_element_css_size(c"canvas".as_ptr().cast(), &mut width, &mut height);
×
60
    (width as u32, height as u32)
×
61
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc