Skip to content

Race condition possible in LoadTextureFromImage from NativeEngine.cpp #1398

@bghgary

Description

@bghgary

for (uint8_t mip = 0; mip < image->m_numMips; ++mip)
{
bimg::ImageMip imageMip{};
if (bimg::imageGetRawData(*image, 0, mip, image->m_data, image->m_size, imageMip))
{
bgfx::ReleaseFn releaseFn{};
if (mip == image->m_numMips - 1)
{
releaseFn = [](void*, void* userData) {
bimg::imageFree(static_cast<bimg::ImageContainer*>(userData));
};
}
const bgfx::Memory* mem{bgfx::makeRef(imageMip.m_data, imageMip.m_size, releaseFn, image)};
texture->Update2D(0, mip, 0, 0, static_cast<uint16_t>(imageMip.m_width), static_cast<uint16_t>(imageMip.m_height), mem);
}
}

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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions