BabylonNative icon indicating copy to clipboard operation
BabylonNative copied to clipboard

Race condition possible in LoadTextureFromImage from NativeEngine.cpp

Open bghgary opened this issue 1 year ago • 1 comments

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.

bghgary avatar Jun 28 '24 16:06 bghgary

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

CedricGuillemet avatar Jul 04 '24 15:07 CedricGuillemet