Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXC_BAD_ACCESS error when using ffi with ffigen to access HealthKit on iOS #451

Closed
ghost opened this issue May 12, 2023 · 4 comments
Closed
Labels
lang-objective_c Related to Objective C support package:ffigen

Comments

@ghost
Copy link

ghost commented May 12, 2023

Hello,

I'm trying to use ffi with ffigen to access HealthKit on iOS. I've included my main.dart and pubspec.yaml files in this gist: https://gist.github.com/jeanantoine/28cc7ff1e9d08fe360e2a720b4be657c

When I run my code, I get the following runtime error:

flutter: #### before executeQuery_
    thread dart-lang/ffigen#3, queue = ‘com.apple.HealthKit.HKHealthStore.client.0x282203670’, stop reason = EXC_BAD_ACCESS (code=1, address=0x10c8c8000) frame #0: 0x000000010c8c8000 error: memory read failed for 0x10c8c8000 Target 0: (Runner) stopped.

Can anyone help me understand what might be causing this error and how I can fix it?

Thank you!

@dcharkes
Copy link
Collaborator

cc @liamappelbe

@liamappelbe
Copy link
Contributor

The crash is probably because your resultsHandler is being called by HealthKit on one of its worker threads. At the moment, callbacks into Dart only work if they're called on the same thread that created the callback.

We're working on fixing it so that callbacks can be called from an arbitrary thread. You can follow the progress of that here: dart-lang/sdk#37022

If you can't wait for that feature to land, the workaround at the moment is to write your results handler in objective C, and then forward the result to the target isolate over a Dart_Port. This is how package:cupertino_http works.

@ghost
Copy link
Author

ghost commented May 15, 2023

@liamappelbe :
thank you for your response. I have a working code with method channel for accessing HealthKit in Swift. I wanted to write the code in Dart only.

@liamappelbe liamappelbe added the lang-objective_c Related to Objective C support label Aug 25, 2023
@liamappelbe
Copy link
Contributor

liamappelbe commented Aug 30, 2023

ObjCBlock.listener has landed: dart-archive/ffigen#601
I'll add a full HealthKit example soon: #448

@liamappelbe liamappelbe transferred this issue from dart-archive/ffigen Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-objective_c Related to Objective C support package:ffigen
Projects
None yet
Development

No branches or pull requests

2 participants