BabylonJS / BabylonNative

Build cross-platform native applications with the power of the Babylon.js JavaScript framework
MIT License
779 stars 133 forks source link

Race condition possible in LoadTextureFromImage from NativeEngine.cpp #1398

Open bghgary opened 5 months ago

bghgary commented 5 months ago

https://github.com/BabylonJS/BabylonNative/blob/6bb77028369d7c91df0372448a6062ea37293b2b/Plugins/NativeEngine/Source/NativeEngine.cpp#L301-L317

The problem is that if Start/FinishRenderingCurrentFrame is being called on the graphics thread, then bgfx::frame can cause releaseFn to be called before this loop is done with image. One possible somewhat hacky solution is to save the image->m_numMips in a local variable to prevent usage of image as it is only possible for the releaseFn to be called on the last mip.

CedricGuillemet commented 4 months ago

Also, the possibility of a memory leak if the last mipmap update goes wrong is a bit scary.