I’m using BabylonJS ReactNative. My code works fine but only one type of behaviour it crashes.
I’ve a Home.tsx
where I’m loading a 3D modal
const engine = useEngine();
const [scene, setScene] = useState<Scene>();
const [camera, setCamera] = useState<Camera>();
useEffect(() => {
if (engine) {
loadGLTF();
}
}, [engine]);
const loadGLTF = () => {
SceneLoader.LoadAsync(GLTF_URL, undefined, engine)
.then(loadedScene => {
if (loadedScene) {
setScene(loadedScene);
// Camera & Light
loadedScene.createDefaultCameraOrLight(true, undefined, true);
const defaultCamera = loadedScene.activeCamera as ArcRotateCamera;
if (defaultCamera) {
defaultCamera.alpha += Math.PI;
setCamera(defaultCamera);
}
}
})
}
const renderLoading = () => {
return (
<View style={styles.absoluteView}>
<ActivityIndicator size="large" />
</View>
);
};
return (
<View style={styles.container}>
<EngineView camera={camera} displayFrameRate={false} />
{!scene && renderLoading()}
</View>
);
The above code works fine if this screen is the first to load when the app launches. If I navigate to this screen it crashes the app as soon as the scene is loaded, so I’m not sure what only in this particular case it crashes I have tried doing the below as well:
{scene && (
<EngineView camera={camera} displayFrameRate={false} />
)}
But in this case, it just keep showsing the loading and nothing happens. For navigation I’m using:
"@react-navigation/native": "6.1.17",
"@react-navigation/stack": "6.4.0",
I’m not sure at this point as to why it would crash in the case when it’s navigated to and not when it’s loaded as the first screen. When it crash the logs are:
#00 pc 0000000000634f48 /data/app/~~FWMFDplcfvO3fHn-S4NWfg==/com.myapp-bkoMAO5bFCkWTXssAwjfcA==/base.apk!libBabylonNative.so (offset 0x1c17000) (BuildId: 745b36b386471bf3e4c7c2585dd63232a023634f)
#01 pc 00000000006229bc /data/app/~~FWMFDplcfvO3fHn-S4NWfg==/com.myapp-bkoMAO5bFCkWTXssAwjfcA==/base.apk!libBabylonNative.so (offset 0x1c17000) (bgfx::createTexture2D(unsigned short, unsigned short, bool, unsigned short, bgfx::TextureFormat::Enum, unsigned long, bgfx::Memory const*)+44) (BuildId: 745b36b386471bf3e4c7c2585dd63232a023634f)
#02 pc 0000000000620864 /data/app/~~FWMFDplcfvO3fHn-S4NWfg==/com.myapp-bkoMAO5bFCkWTXssAwjfcA==/base.apk!libBabylonNative.so (offset 0x1c17000) (Babylon::Graphics::Texture::Create2D(unsigned short, unsigned short, bool, unsigned short, bgfx::TextureFormat::Enum, unsigned long)+140) (BuildId: 745b36b386471bf3e4c7c2585dd63232a023634f)
#03 pc 0000000000362ddc /data/app/~~FWMFDplcfvO3fHn-S4NWfg==/com.myapp-bkoMAO5bFCkWTXssAwjfcA==/base.apk!libBabylonNative.so (offset 0x1c17000) (BuildId: 745b36b386471bf3e4c7c2585dd63232a023634f)
#04 pc 0000000000373ff0 /data/app/~~FWMFDplcfvO3fHn-S4NWfg==/com.myapp-bkoMAO5bFCkWTXssAwjfcA==/base.apk!libBabylonNative.so (offset 0x1c17000) (BuildId: 745b36b386471bf3e4c7c2585dd63232a023634f)
#05 pc 0000000000374108 /data/app/~~FWMFDplcfvO3fHn-S4NWfg==/com.myapp-bkoMAO5bFCkWTXssAwjfcA==/base.apk!libBabylonNative.so (offset 0x1c17000) (arcana::internal::task_payload_with_work<void, std::exception_ptr, 56ul>::do_work(arcana::internal::base_task_payload&, arcana::internal::base_task_payload*)+60) (BuildId: 745b36b386471bf3e4c7c2585dd63232a023634f)
#06 pc 000000000037428c /data/app/~~FWMFDplcfvO3fHn-S4NWfg==/com.myappbkoMAO5bFCkWTXssAwjfcA==/base.apk!libBabylonNative.so (offset 0x1c17000) (BuildId: 745b36b386471bf3e4c7c2585dd63232a023634f)