Closed temeddix closed 1 year ago
So casting to isize
made that zero number to be a very big number like 140208384468704
? huh weird, I guess thats why using as
is bad.
Did you test this branch with your code? is that fixes your bug?
I tested with the code provided in this issue, which should obviously work. The code just simply involved passing zero-length Vec<T>
s. I confirmed that with my forked allo-isolate
, zero-length Vec<T>
with zero-copy
works properly.
Will publish a new version very soon.
Thanks for notifying :)
Published as v0.1.20 🎉
Summary
When enabling the
zero-copy
feature or usingZeroCopyBuffer
,Vec<T>
with length of 0 always made the Dart-Rust app crash. This turned out to be a behavior withisolate_callback_data
, which returns proper length value when the length ofVec<T>
was not 0, but returns an oddly big number whenVec<T>
has zero length.https://github.com/cunarist/rust-in-flutter/issues/165
Experiment
Adding some
println!()
s can help us inspect this problem.When passing in
Vec<T>
of 6 bytes withzero-copy
feature enabled(or usingZeroCopyBuffer
), we get this output:When passing in
Vec<T>
of 0 bytes withzero-copy
feature enabled(or usingZeroCopyBuffer
), we get this output:The length value from Rust
Vec<T>
is correct, but the length value fromisolate_callback_data
is very weird. This led to deallocating memory of a totally wrong location which always made the Dart-Rust app crash.I've confirmed that this change effectively works on an actual project that uses
Vec<T>
of length 0 withzero-copy
. Tests are also added in this PR.