Skip to content
Discussion options

You must be logged in to vote

The callback=NaN log is a red herring — that's expected, not the bug.

In Perry, function values are NaN-boxed: the f64 bit pattern is 0x7FFD_0000_0000_0000 | (ptr & 0xFFFF_FFFF_FFFF). That's a quiet NaN by IEEE-754 construction, so eprintln!("{:?}", cb_f64) prints NaN for any function/object/string value. The bits underneath still hold the pointer. (Switch your logs to eprintln!("{:#x}", cb.to_bits()) and you'll see 7ffd… for closures, 7fff… for strings, etc.)

The actual bug is in your invocation in audio.rs:

let cb_bits = cb.to_bits();
let closure_ptr = cb_bits as *const u8;          // ← keeps the 0x7FFD tag in the high bits
js_closure_call2(closure_ptr, samples_ptr_val, num_samples_val);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by proggeramlug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants