BabylonNative: Playground demo: crash on MacOS/iOS in NAPI_THROW_IF_FAILED for OSX Mojave and iOS 12

Related to https://github.com/BabylonJS/BabylonNative/issues/165

Commit:922b1eebd59b58ae2618f54141d491ff55f3ff43 [922b1ee] but it was still occurring several commits back. MacBook Pro (15-inch, 2018) MacOS Mojave 10.14.6 XCode Version 11.3 Python 3.7.7 cmake version 3.17.0 Followed the directions on the Readme.

Running Playground app from Xcode both iOS and OSX, loader.LoadScript("babylon.max.js"); is called. NAPI_THROW_IF_FAILED(env, napi_run_script(env, Napi::String::New(env, string), sourceUrl, &result)); throws at OpaqueJSValue *retValue = const_cast<OpaqueJSValue*>(JSEvaluateScript(env->m_globalContext, statement, nullptr, JSStringCreateWithUTF8CString(sourceUrl), 1, &exception));

Screen Shot 2020-03-31 at 3 19 09 PM

Since I have bootcamp and Windows 10 VS2019, I tried it there and the Playground worked. Someone I know has the same hardware but on Catalina(10.15.4) and XCode 11.4 and the Playground worked without issues on both OSX and iOS.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

Thanks @bghgary - I put that fix in:

napi_status napi_run_script(napi_env env,
              napi_value script,
              const char* sourceUrl,
              napi_value* result) {
  JSStringRef statement = JSValueToStringCopy(env->m_globalContext, reinterpret_cast<JSValueRef>(script), nullptr);
  JSValueRef exception;
  OpaqueJSValue *retValue = const_cast<OpaqueJSValue*>(JSEvaluateScript(env->m_globalContext, statement, nullptr, JSStringCreateWithUTF8CString(sourceUrl), 1, &exception));
  if (!retValue) {
    DumpException(env, exception);
  }
  *result = reinterpret_cast<napi_value>(retValue);
  return napi_ok;
}

And the playground runs without crashing on Mojave (10.14.6).

Tested with the change from @bnolan, also works for me ! Thanks !

Don’t forget to add:

JSStringRelease(statement);

Thanks for helping with testing @imbrig! One of things that this project can use more of is testing. In general, I think we would like to support as many versions as possible, so we will look into this more.

I have not tested the tip yet, but will do that soon.

@bghgary My test device is an iphone 8 with (12.2) which was running into that throw. I tried my personal iphone XS with (13.3) and it worked and did not encounter the throw.

So the take away for me was on OSX Mojave (10.14.6) and iOS (12) run into the throw, while OSX Catalina (10.15.4) and iOS (13) work perfectly.

retested on my side with tip, same issue (ScriptLoader::Eval -> NAPI::Eval -> napi_run_script() -> crash). If I comment loader.Eval("document = {}", ""); in ViewController.mm, it will crash later at the same place in napi_run_script() but now called from ScriptLoader::LoadScript.

The first comment said commit 922b1ee which is the tip of master.

@bghgary I celebrated too early, while OSX did work I got the same throw on iOS. Here’s the value of env->m_globalContext Screen Shot 2020-03-31 at 6 06 29 PM

Could be that something strange is going on with my xcode frameworks or toolchain which I did not edit anything but that’s a possibility. I’ll be installing 11.4 to see if that fixes things.

@bghgary I’m sorry, but I’ve updated to Catalina 10.15.4 and with just that, everything works and nothing is being thrown on OSX. I’m going to test iOS but I think that it’ll also work there.