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.
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 withimage
. One possible somewhat hacky solution is to save theimage->m_numMips
in a local variable to prevent usage ofimage
as it is only possible for thereleaseFn
to be called on the last mip.