Skip to content

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

Description

@matos-claudio

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions