Closed mrousavy closed 3 years ago
Hmm, not even this code works:
jsiRuntime.global().setProperty(jsiRuntime, "teeeeeeeest", jsi::Value(42));
maybe the runtime pointer is corrupted?
Hi @mrousavy, is it possible that the copy of JSI being used does not line up with the version of Hermes being used? It seems suspicious that facebook::jsi::Function::createFromHostFunction
is calling facebook::hermes::HermesRuntimeImpl::call
. I noticed your build is using JSI from an RN checkout in another directory, is that checkout at the corresponding version?
Okay so I did a bit of investigation and it seems like this error is also happening with JSC. Looks like I was wrong ticking that box above, sorry!
I am still not sure why this keeps happening, do you maybe have an idea @neildhar?
A lot of people report this issue, with kind-of different crash logs https://github.com/mrousavy/react-native-mmkv/issues/88, https://github.com/mrousavy/react-native-mmkv/issues/122, https://github.com/mrousavy/react-native-mmkv/issues/111 or https://github.com/mrousavy/react-native-mmkv/issues/98
I'm essentially just installing a single function in the jsi::Runtime
before the JS bundle starts executing, and I achieve this by
JSIModulePackage
, overriding the getJSIModules
function and calling the native C++ function with the passed JavaScriptContextHolder.get()
pointer. (see code here)reinterpret_cast
the long
JS Context pointer to a jsi::Runtime*
(see code here)jsi::Function
from a Host Function and calls .global().setProperty(..)
(see code here).Apparently for some people accessing .global()
crashes, while for others jsi::Function::createFromHostFunction
crashes.
This seems so weird to me, maybe I got the jsi::Runtime
wrong and it's an invalid pointer?
Maybe also important: my CMakeLists.txt
and my build.gradle
.
Apparently it works on RN 0.65.1, but crashes on RN 0.64.2....
Looks like we're talking about this error: https://github.com/facebook/hermes/blob/6e5868763b08eb80f4164a926abb92fa5c71117f/API/hermes/hermes.cpp#L2003-L2009
why does count
get range checked here, aren't those the function arguments?
I don't believe it should be calling HermesRuntimeImpl::call
at all, did you check the version of JSI being used as mentioned in my previous comment? The fact that it works on 0.65.1 but not on 0.64 also lines up with the possibility that you're using JSI from a checkout of RN that is on the 0.65 branch or main
.
JSI can change from one version of RN to another, so you need to build your plugin against JSI from the right version of RN.
Oh I'm sorry I misunderstood the previous comment about the JSI version! That makes sense, I might have to distribute react-native-mmkv as source instead of prebuilding it on my machine (.aar). I thought this would not link it against RN/JSI but apparently it does.
I guess since this is unrelated to hermes we can close this now, thanks for your help.
Bug Description
I am trying to create a new host function and install it in the JSI runtime's global object, but everytime I try to do that, my app crashes (SIGABRT).
gradle clean
and confirmed this bug does not occur with JSCHermes version: 0.7.0 React Native version (if any): 0.64.0 OS version (if any): Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64-v8a
Steps To Reproduce
code example:
Full code in mrousavy/react-native-mmkv (
feat/mmkv-host-object
branch)The Expected Behavior
I expect the function to be installed without problems.
The Android Logcat output: