BabylonReactNative: Failing to create GlContext on Android emulator with Playground 0.65

Hi there,

I’m trying to build and run the Playground 0.65 sample from the BabylonReactNative GitHub repo (main branch). I runs fine on my Android phone and with the emulator on my laptop. However it crashes on my main development machine when running in the emulator.

I’m using the following command:

npx react-native run-android

Using logcat, here are the first few lines of the callstack

(Babylon::BgfxCallback::fatal(char const*, unsigned short, bgfx::Fatal::Enum, char const*)+190) (BuildId: 27be7ec5318f6dd0b1443ea85b268fe3927a5cea)
(bgfx::fatal(char const*, unsigned short, bgfx::Fatal::Enum, char const*, ...)+403) (BuildId: 27be7ec5318f6dd0b1443ea85b268fe3927a5cea)
(bgfx::gl::GlContext::create(unsigned int, unsigned int)+1248) (BuildId: 27be7ec5318f6dd0b1443ea85b268fe3927a5cea)
(bgfx::gl::RendererContextGL::setRenderContextSize(unsigned int, unsigned int, unsigned int)+146) (BuildId: 27be7ec5318f6dd0b1443ea85b268fe3927a5cea)
(bgfx::gl::RendererContextGL::init(bgfx::Init const&)+310) (BuildId: 27be7ec5318f6dd0b1443ea85b268fe3927a5cea)
(bgfx::gl::rendererCreate(bgfx::Init const&)+171) (BuildId: 27be7ec5318f6dd0b1443ea85b268fe3927a5cea)
(bgfx::rendererCreate(bgfx::Init const&)+376) (BuildId: 27be7ec5318f6dd0b1443ea85b268fe3927a5cea)

I’m running on Win10 21H2 with a GTX 980Ti and up-to-date drivers.

As a side note, after cloning a fresh repo, the build always fail on the first time with an out of memory Java exception. My machine has 32GB of memory with only 50% used.

Thanks for your help!

cc @bghgary and @ryantrem

Do you have the message string from the fatal function? Android emulators can be quite finicky. Does this repro with a physical device?

No I don’t have the message, but I’m new to Android dev. Can you let me know how to retrieve it?

The same project works on another (older) Win10 machine and on my phone.

It should be in the log. If not, if you can put an exception breakpoint, it should stop there.

Does it crash also if you use a physical device on the machine that crashes with the emulator?

There is trouble shooting doc with the emulator here : BabylonNative/AndroidEmulator.md at master · BabylonJS/BabylonNative · GitHub

1 Like

Thank you @bghgary and @Cedric for your help!
For some reason the emulator has become unresponsive, so I’ve deleted it and created a new one (same settings), and now it’s working… I’ll remember to re-create an emulator the next time I have an unexpected low level failure :slight_smile:

[Edit] Actually it’s not re-creating the emulator image that fixed the problem, but changing the Open GL ES API level from “default” to maximum as suggested in the documentation link posted above.
I didn’t realized this setting change had carried over from the previous (non functioning) image to the new one.

3 Likes

We should link to the Android emulator troubleshooting doc from the Babylon React Native docs. I added a note about this to Update documentation for Babylon React Native release · Issue #1017 · BabylonJS/BabylonNative (github.com)

1 Like