react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

Multiple callback calls in C++ Native Module crashes app

Open ClaudiuHBann opened this issue 3 years ago • 0 comments

Problem Description

When you call a method, async or not, from a C++ native module which contains multiple invokes to the provided callback, the app crashes. A small example of a method:

REACT_METHOD(Add, L"add");
  void Add(std::function<void(double)> callback) noexcept
  {
    callback(69.);
    callback(69.);
  }

I will provide a full example below so you can try it yourself easier.

Steps To Reproduce

  1. create a default RNW app like this
  2. create a simple C++ native module like this
  3. call the method from react native

Expected Results

In the example from the steps I provided I expected 2 console logs not a crash :))

CLI version

8.0.6

Environment

System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
    Memory: 9.13 GB / 15.36 GB
  Binaries:
    Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
      Versions: 10.0.18362.0, 10.0.19041.0, 10.0.20348.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 17.3.32825.248 (Visual Studio Community 2022)
  Languages:
    Java: 11.0.12 - C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: Not Found
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Target Platform Version

10.0.19041

Target Device(s)

Desktop, HoloLens

Visual Studio Version

Visual Studio 2022

Build Configuration

Debug

Snack, code example, screenshot, or link to a repository

https://github.com/ClaudiuHBann/RNW_Test

ClaudiuHBann avatar Sep 22 '22 23:09 ClaudiuHBann