margelo / margelo/react-native-fast-tflite

[iOS] EXC_BAD_ACCESS in bridgeless mode - runtime captured by reference in async lambda

Open
#169 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.2k
Forks
92
Avg merge
13h 9m
Merged PRs (30d)
2

Description

Environment

  • react-native-fast-tflite: 2.0.0
  • React Native: 0.84 (bridgeless mode)
  • iOS

Problem

TensorflowPlugin.cpp captures runtime by reference ([=, &runtime])
in async lambdas passed to callInvoker->invokeAsync. When the lambda
executes asynchronously, the runtime reference is dangling — causing
EXC_BAD_ACCESS.

Two occurrences:

  1. callInvoker->invokeAsync([=, &runtime]() { ← loadTensorflowModel
  2. this->_callInvoker->invokeAsync([=, &runtime]() { ← run()

Fix

Capture runtime by pointer instead:

// BEFORE
callInvoker->invokeAsync([=, &runtime]() {
  auto result = jsi::Object::createFromHostObject(runtime, plugin);
  promise->resolve(std::move(result));
});

// AFTER  
auto* runtimePtr = &runtime;
callInvoker->invokeAsync([=]() {
  auto result = jsi::Object::createFromHostObject(*runtimePtr, plugin);
  promise->resolve(std::move(result));
});

Same fix for the second occurrence in run().

Workaround

Use react-native-nitro-tflite (unofficial drop-in replacement).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in TensorflowPlugin.cpp and inspect the asynchronous callInvoker invocations in loadTensorflowModel and run(), focusing on how runtime is captured. Confirm both occurrences no longer rely on a dangling reference, then build or test the iOS bridgeless configuration and verify the EXC_BAD_ACCESS issue is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, ios, react-native, tensorflow
Domain
machine-learning, mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.