BabylonNative icon indicating copy to clipboard operation
BabylonNative copied to clipboard

NativeEngine contains thread-unsafe logic that causes crashes during fast refresh BabylonReactNative scenarios

Open chrisfromwork opened this issue 5 years ago • 3 comments

We have logic in NativeEngine that hands around an allocator that is not valid when NativeEngine is disposed: https://github.com/BabylonJS/BabylonNative/blob/720b2dc2da8393aad4893a1661dd71bef1aa6fdc/Plugins/NativeEngine/Source/NativeEngine.cpp#L981

This logic does not observe cancellation requests and can generate crashes during fast refresh/NativeEngine teardown

chrisfromwork avatar Mar 15 '21 19:03 chrisfromwork

Chatted with @ryantrem offline. Seems like the following is going on:

"this seems related to the conversation we just had.... NativeEngine is owned by the JS side but tries to do work on a thread other than the JS thread, and so NativeEngine can be destructed while those async operations are executing. m_allocator, m_cancellationToken, and m_runtimeScheduler are all not safe to use in this way. Either lifetimes need to be extended or some of this stuff needs to move out of NativeEngine to something longer lived."

chrisfromwork avatar Mar 15 '21 19:03 chrisfromwork

This can happen, for example, when an async LoadTexture is in progress and the NativeEngine is disposed (or maybe when bgfx is shutdown via Graphics::DisableRendering).

ryantrem avatar Jun 22 '21 17:06 ryantrem

Affected by https://github.com/microsoft/arcana.cpp/pull/36.

syntheticmagus avatar Apr 14 '22 18:04 syntheticmagus