cunarist / rinf

Rust for native business logic, Flutter for flexible and beautiful GUI
MIT License
1.99k stars 72 forks source link

FfiException(PANIC_ERROR, called `Option::unwrap()` on a `None` value, null) #224

Closed erlangparasu closed 11 months ago

erlangparasu commented 11 months ago

Report

`Option::unwrap()` on a `None` value, null)

Got this log error when trigger onTap

Steps to Reproduce

Please describe the exact steps to reproduce the error.

rinf message
brew install protobuf  
flutter run
                onTap: () async {
                  try {
                    final requestMessage = tutorial_resource.ReadRequest(
                      letter: 'Hello',
                      beforeNumber: 1,
                      dummyOne: 1,
                      dummyTwo: tutorial_resource.SampleSchema(
                        sampleFieldOne: true,
                        sampleFieldTwo: false,
                      ),
                      dummyThree: [],
                    );
                    final rustRequest = RustRequest(
                      resource: tutorial_resource.ID,
                      operation: RustOperation.Read,
                      message: requestMessage.writeToBuffer(),
                    );

                    printWrapped('aaaa');
                    final rustResponse = await requestToRust(rustRequest);
                    printWrapped('bbbb');
                    final responseMessage = tutorial_resource.ReadResponse.fromBuffer(
                      rustResponse.message!,
                    );
                    printWrapped('after=${responseMessage.afterNumber}');
                  } catch (e, trace) {
                    rethrow;
                  }
                },

System Information

Please provide the output from the command below, using markdown codeblock syntax.

rustc --version
rustc 1.74.0 (79e9716c9 2023-11-13)

protoc --version
libprotoc 25.1

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.0, on macOS 13.6 22G120 darwin-arm64, locale en-ID)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    ✗ Unable to get list of installed Simulator runtimes.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.84.2)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 1 category.
temeddix commented 11 months ago

Hi @erlangparasu , thanks for the report :)

I can come up with one possibility. Can you check if you initialized Rust logic from the Dart side, like this?

https://github.com/cunarist/rinf/blob/5b3c23395b3066bebf739a7534a440e48bb884dd/flutter_ffi_plugin/example/lib/main.dart#L7-L11

erlangparasu commented 11 months ago

@temeddix oh Thanks so much!