From 48f936ca723c7f6d7f77afb948701b85dac50492 Mon Sep 17 00:00:00 2001 From: Ryan Tremblay Date: Thu, 8 Oct 2020 14:55:03 -0700 Subject: [PATCH 1/2] Update to latest Babylon.js Update to latest Babylon Native Switch iOS to use setTimeout to indirectly get the queue flushed, as calling it directly breaks internal UI state Remove the workaround in Android that re-initializes the graphics after initializing as this is no longer an issue --- Apps/PackageTest/package-lock.json | 6 ++--- Apps/PackageTest/package.json | 2 +- Apps/Playground/package-lock.json | 22 +++++++++---------- Apps/Playground/package.json | 4 ++-- .../src/main/cpp/BabylonNativeInterop.cpp | 3 --- .../react-native/ios/BabylonNative.cpp | 10 ++++----- Modules/@babylonjs/react-native/package.json | 2 +- .../@babylonjs/react-native/shared/Shared.h | 12 ++++++++++ .../react-native/submodules/BabylonNative | 2 +- 9 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Apps/PackageTest/package-lock.json b/Apps/PackageTest/package-lock.json index 86a5997a2..1bfecdcd1 100644 --- a/Apps/PackageTest/package-lock.json +++ b/Apps/PackageTest/package-lock.json @@ -908,9 +908,9 @@ } }, "@babylonjs/core": { - "version": "4.2.0-beta.6", - "resolved": "https://registry.npmjs.org/@babylonjs/core/-/core-4.2.0-beta.6.tgz", - "integrity": "sha512-oLAgv37Gjept9yMjyJ2EuTYWe96JAYTfdJdW3MAbcafg4TmMv/gOLBqP6a62pOmxZyEJ35bX9A8NNvTb/5R/Xg==", + "version": "4.2.0-beta.10", + "resolved": "https://registry.npmjs.org/@babylonjs/core/-/core-4.2.0-beta.10.tgz", + "integrity": "sha512-OnfQQfhbUrGYEOKSEgmvgqQ5ZHockWUXyn0F488HTvUHB1/iaPlh9UAAsNYCEphIT0exlg3bFmJ1ZGfZyxAhmw==", "requires": { "tslib": ">=1.10.0" } diff --git a/Apps/PackageTest/package.json b/Apps/PackageTest/package.json index 99d01784a..a84c08d21 100644 --- a/Apps/PackageTest/package.json +++ b/Apps/PackageTest/package.json @@ -10,7 +10,7 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { - "@babylonjs/core": "^4.2.0-beta.6", + "@babylonjs/core": "^4.2.0-beta.10", "@babylonjs/react-native": "file:../../Package/Assembled/babylonjs-react-native-0.0.1.tgz", "react": "16.13.1", "react-native": "0.63.1", diff --git a/Apps/Playground/package-lock.json b/Apps/Playground/package-lock.json index c137de960..9d83ff74b 100644 --- a/Apps/Playground/package-lock.json +++ b/Apps/Playground/package-lock.json @@ -864,20 +864,20 @@ } }, "@babylonjs/core": { - "version": "4.2.0-beta.6", - "resolved": "https://registry.npmjs.org/@babylonjs/core/-/core-4.2.0-beta.6.tgz", - "integrity": "sha512-oLAgv37Gjept9yMjyJ2EuTYWe96JAYTfdJdW3MAbcafg4TmMv/gOLBqP6a62pOmxZyEJ35bX9A8NNvTb/5R/Xg==", + "version": "4.2.0-beta.10", + "resolved": "https://registry.npmjs.org/@babylonjs/core/-/core-4.2.0-beta.10.tgz", + "integrity": "sha512-OnfQQfhbUrGYEOKSEgmvgqQ5ZHockWUXyn0F488HTvUHB1/iaPlh9UAAsNYCEphIT0exlg3bFmJ1ZGfZyxAhmw==", "requires": { "tslib": ">=1.10.0" } }, "@babylonjs/loaders": { - "version": "4.2.0-beta.6", - "resolved": "https://registry.npmjs.org/@babylonjs/loaders/-/loaders-4.2.0-beta.6.tgz", - "integrity": "sha512-3n4TD9FgZIyJ6PFhqi6HFm2GlDLAhgszm1lGAb+CCXqiqgHqfApvNO4Q0d+sm+emK820LQukTgowWWlJKwgJZw==", + "version": "4.2.0-beta.10", + "resolved": "https://registry.npmjs.org/@babylonjs/loaders/-/loaders-4.2.0-beta.10.tgz", + "integrity": "sha512-rE0Pe/Ov3LiycXnfyrP2j90USEUOX9rRS7roQoCNCib4DpmN1EebXhJqmdu1dRmpuP9wKUsTXPm0JMgRxz/7RA==", "requires": { - "@babylonjs/core": "4.2.0-beta.6", - "babylonjs-gltf2interface": "4.2.0-beta.6", + "@babylonjs/core": "4.2.0-beta.10", + "babylonjs-gltf2interface": "4.2.0-beta.10", "tslib": ">=1.10.0" } }, @@ -3053,9 +3053,9 @@ } }, "babylonjs-gltf2interface": { - "version": "4.2.0-beta.6", - "resolved": "https://registry.npmjs.org/babylonjs-gltf2interface/-/babylonjs-gltf2interface-4.2.0-beta.6.tgz", - "integrity": "sha512-ppH5R2SPaZ9EHfVZAdi3Fb/s0n/vtle1XWy4BMiTKsnRuZXNwKtruRkdT9sAO6D5xw2ZJ0S1gSuz0JXaCo3AAw==" + "version": "4.2.0-beta.10", + "resolved": "https://registry.npmjs.org/babylonjs-gltf2interface/-/babylonjs-gltf2interface-4.2.0-beta.10.tgz", + "integrity": "sha512-Bi0LFfLlBAiP1urxd2PEtyJIESEWg/fiugOLGDIgJAnebXR5++LSpxOuhuDmXC1Gql+bO5Dp8AW8JwQqp+dPTg==" }, "balanced-match": { "version": "1.0.0", diff --git a/Apps/Playground/package.json b/Apps/Playground/package.json index e020b3e56..015d06318 100644 --- a/Apps/Playground/package.json +++ b/Apps/Playground/package.json @@ -10,8 +10,8 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { - "@babylonjs/core": "^4.2.0-beta.6", - "@babylonjs/loaders": "^4.2.0-beta.6", + "@babylonjs/core": "^4.2.0-beta.10", + "@babylonjs/loaders": "^4.2.0-beta.10", "@babylonjs/react-native": "file:../../Modules/@babylonjs/react-native", "@react-native-community/slider": "^2.0.9", "logkitty": "^0.7.1", diff --git a/Modules/@babylonjs/react-native/android/src/main/cpp/BabylonNativeInterop.cpp b/Modules/@babylonjs/react-native/android/src/main/cpp/BabylonNativeInterop.cpp index 0e87a009e..e9013f92b 100644 --- a/Modules/@babylonjs/react-native/android/src/main/cpp/BabylonNativeInterop.cpp +++ b/Modules/@babylonjs/react-native/android/src/main/cpp/BabylonNativeInterop.cpp @@ -80,9 +80,6 @@ namespace Babylon Polyfills::Window::Initialize(m_env); m_nativeInput = &Babylon::Plugins::NativeInput::CreateForJavaScript(m_env); - - // TODO: This shouldn't be necessary, but for some reason results in a significant increase in frame rate. Need to figure this out. - m_graphics->ReinitializeFromWindow(windowPtr, width, height); } ~Native() diff --git a/Modules/@babylonjs/react-native/ios/BabylonNative.cpp b/Modules/@babylonjs/react-native/ios/BabylonNative.cpp index b427c9cc7..35656a5b7 100644 --- a/Modules/@babylonjs/react-native/ios/BabylonNative.cpp +++ b/Modules/@babylonjs/react-native/ios/BabylonNative.cpp @@ -48,22 +48,22 @@ namespace Babylon struct DispatchData { arcana::run_loop_scheduler scheduler; - Napi::FunctionReference flushedQueue; + std::shared_ptr setTimeout; - DispatchData(Napi::Env env) + DispatchData(facebook::jsi::Runtime& rt) : scheduler{ arcana::run_loop_scheduler::get_for_current_thread() } - , flushedQueue{ GetFlushedQueue(env) } + , setTimeout{ GetSetTimeout(rt) } { } }; JsRuntime::DispatchFunctionT dispatchFunction = - [env = m_impl->env, data = std::make_shared(m_impl->env)](std::function func) + [env = m_impl->env, data = std::make_shared(*jsiRuntime)](std::function func) { (data->scheduler)([env, func = std::move(func), &data]() { func(env); - data->flushedQueue.Call({}); + data->setTimeout->call((static_cast(env))->rt, {}); }); }; diff --git a/Modules/@babylonjs/react-native/package.json b/Modules/@babylonjs/react-native/package.json index 79562086d..c47e7f8f7 100644 --- a/Modules/@babylonjs/react-native/package.json +++ b/Modules/@babylonjs/react-native/package.json @@ -27,7 +27,7 @@ "base-64": "^0.1.0" }, "peerDependencies": { - "@babylonjs/core": "^4.2.0-beta.6", + "@babylonjs/core": "^4.2.0-beta.10", "react": "^16.13.1", "react-native": "^0.63.1", "react-native-permissions": "^2.1.4" diff --git a/Modules/@babylonjs/react-native/shared/Shared.h b/Modules/@babylonjs/react-native/shared/Shared.h index dcaef312b..f8e4e9093 100644 --- a/Modules/@babylonjs/react-native/shared/Shared.h +++ b/Modules/@babylonjs/react-native/shared/Shared.h @@ -1,6 +1,7 @@ #pragma once #include +#include // See https://github.com/BabylonJS/BabylonReactNative/issues/60 for original issue. // This is a work around to poke the React Native message queue to run setImmediate callbacks. @@ -16,3 +17,14 @@ inline Napi::FunctionReference GetFlushedQueue(Napi::Env env) auto flushedQueue{ batchedBridge.Get("flushedQueue").As() }; return Napi::Persistent(flushedQueue); } + +// On iOS, directly calling flushedQueue breaks some kind of internal UI state and we start getting errors like: +// *** Assertion failure in -[RCTNativeAnimatedNodesManager disconnectAnimatedNodes:childTag:](), node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m:138 +// [native] Exception thrown while executing UI block: 'parentNode' is a required parameter +// However, calling setTimeout eventually also calls flushedQueue, but doesn't result in the above error, +// so we'll go this route until we (hopefully) get a better resolution from the React Native team at Facebook. +inline std::shared_ptr GetSetTimeout(facebook::jsi::Runtime& rt) +{ + auto code{std::make_shared("() => setTimeout(() => {})")}; + return std::make_shared(rt.evaluateJavaScript(std::move(code), "").asObject(rt).asFunction(rt)); +} diff --git a/Modules/@babylonjs/react-native/submodules/BabylonNative b/Modules/@babylonjs/react-native/submodules/BabylonNative index 106e2af73..410d5cc38 160000 --- a/Modules/@babylonjs/react-native/submodules/BabylonNative +++ b/Modules/@babylonjs/react-native/submodules/BabylonNative @@ -1 +1 @@ -Subproject commit 106e2af739f964f7df9892755232bb7241ad63c8 +Subproject commit 410d5cc38fe219350220b6fffc9b12e5f8e76e7b From 0da5e654ecc9e0b21c172f30e9cfa4e577999561 Mon Sep 17 00:00:00 2001 From: Ryan Tremblay Date: Thu, 8 Oct 2020 15:24:49 -0700 Subject: [PATCH 2/2] Fix bad commit on submodule update --- Modules/@babylonjs/react-native/submodules/BabylonNative | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/@babylonjs/react-native/submodules/BabylonNative b/Modules/@babylonjs/react-native/submodules/BabylonNative index 410d5cc38..914591ae2 160000 --- a/Modules/@babylonjs/react-native/submodules/BabylonNative +++ b/Modules/@babylonjs/react-native/submodules/BabylonNative @@ -1 +1 @@ -Subproject commit 410d5cc38fe219350220b6fffc9b12e5f8e76e7b +Subproject commit 914591ae2005feaebcfafded68f9b9f7cf7b770f