fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.

Home Page:https://fzyzcjy.github.io/flutter_rust_bridge/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Try to use `RustArc<dynamic>` after it has been disposed

kjzl opened this issue · comments

Describe the bug

I made a minimal reproducible project to my problem and I am having trouble understanding what I am doing wrong.
I mainly use frb with Web, but also tested if the problem occurs with the project compiled to linux, which it does for me.

I uploaded the few necessary files to reproduce my issue. Just create a new frb project and paste the source files.
frb_problem.zip

When the Widgets build first, everything displays as expected, when they rebuild I get the error Try to use RustArc<dynamic> after it has been disposed.
The State from which the widgets are being built is held in a frb struct on the dart side using get_it.

PS: When compiling to linux I encountered this issue as it seems, for which a fix was already merged, which has me wondering whether this project includes a outdated version of cargokit and how one is supposed to update it?

Steps to reproduce

  1. flutter_rust_bridge_codegen generate && flutter run
  2. click the 'refresh' Button
  3. Exception is thrown

Logs

-

Expected behavior

No response

Generated binding code

No response

OS

Linux

Version of flutter_rust_bridge_codegen

2.0.0-dev.25

Flutter info

No response

Version of clang++

No response

Additional context

No response

Hi, it would be great to make it a github repo to make it easy to view :) I will check it then

PS: When compiling to linux I encountered irondash/cargokit#57 as it seems, for which a fix was already merged, which has me wondering whether this project includes a outdated version of cargokit and how one is supposed to update it?

Just copy-paste latest cargokit to replace the old one in your project folder. Cargokit has not been published as a standard flutter package, so it is not possible to upgrade using pubspec.yaml etc yet.

I see: https://github.com/kjzl/frb_dropped_arc_min_reproducible/blob/84cbd5da067627bda4fe49826d71b1c178edf6d4/rust/src/api/arc_problem.rs#L44C12-L44C29 make it #[frb(opaque)], which seems the same as #1778. I may need to think about how to improve the API design.

Great, thank you!

You are welcome!

I believe the changes introduced in #1805 result in undesired behavior. In case one creates a opaque struct which is to be stored inside another struct/enum it also becomes opaque by default.
Consider the following scenario where my enum Baz will be made opaque by default in the newest version of frb:

#[flutter_rust_bridge::frb(opaque)]
pub struct Foo(...);
impl Foo {...}

#[flutter_rust_bridge::frb(opaque)]
pub struct Bar(...);
impl Bar {...}

pub enum Baz {
    FooVariant(Foo),
    BarVariant(Bar),
}

Can one somehow force a type to be non-opaque?

Yes, by #[frb(non_opaque)] pub enum Baz.