Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions native/android/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,24 +1353,16 @@ pub extern "C" fn bloom_file_exists(path_ptr: *const u8) -> f64 {
#[no_mangle]
pub extern "C" fn bloom_read_file(path_ptr: *const u8) -> *const u8 {
let path = str_from_header(path_ptr);
// Always return a valid Perry string. A null pointer would NaN-box into a
// string-typed value pointing at address 0; subsequent `.length` /
// `.charCodeAt` reads dereference the bogus StringHeader and segfault.
// Callers detect "missing file" via `data.length === 0` (e.g. the jump
// game's discoverLevels probe across level1..level10 / custom_*).
// Parity with native/linux — Android previously returned null on Err,
// crashing discoverLevels at the first non-existent level file.
match std::fs::read_to_string(resolve_path(path)) {
Ok(contents) => {
// Return Perry-format string: StringHeader (length u32 + capacity u32 + refcount u32) followed by UTF-8 data
let bytes = contents.as_bytes();
let len = bytes.len();
let total = 12 + len; // 12 bytes header (3 × u32) + data
let layout = std::alloc::Layout::from_size_align(total, 4).unwrap();
unsafe {
let ptr = std::alloc::alloc(layout);
if ptr.is_null() { return std::ptr::null(); }
*(ptr as *mut u32) = len as u32; // length
*(ptr.add(4) as *mut u32) = len as u32; // capacity
*(ptr.add(8) as *mut u32) = 1; // refcount (unique)
std::ptr::copy_nonoverlapping(bytes.as_ptr(), ptr.add(12), len);
ptr
}
}
Err(_) => std::ptr::null(),
Ok(contents) => alloc_perry_string(&contents),
Err(_) => alloc_perry_string(""),
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bloomengine/engine",
"version": "0.4.15",
"version": "0.4.16",
"description": "Bloom Engine: native TypeScript game engine compiled by Perry",
"main": "src/index.ts",
"types": "src/index.ts",
Expand Down
Loading