mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Examples: change order of calls in loadTexture() (#3281)
Fixes possible concurrency issue - makes code usable in a multithreaded environment. imageReleasCb releases imageContainer after bgfx::createTexture...() is called. If bgfx::frame() is called from another thread, the release can happen before imageContainer is used in bgfx::calcTextureSize(), leading to a crash. Although loadTexture() is not used in multithreaded environment in the examples, calling bgfx::calcTextureSize() before bgfx::createTexture...() is a better reference for users.
This commit is contained in:
@@ -185,6 +185,20 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const bx::FilePath& _f
|
||||
);
|
||||
unload(data);
|
||||
|
||||
if (NULL != _info)
|
||||
{
|
||||
bgfx::calcTextureSize(
|
||||
*_info
|
||||
, uint16_t(imageContainer->m_width)
|
||||
, uint16_t(imageContainer->m_height)
|
||||
, uint16_t(imageContainer->m_depth)
|
||||
, imageContainer->m_cubeMap
|
||||
, 1 < imageContainer->m_numMips
|
||||
, imageContainer->m_numLayers
|
||||
, bgfx::TextureFormat::Enum(imageContainer->m_format)
|
||||
);
|
||||
}
|
||||
|
||||
if (imageContainer->m_cubeMap)
|
||||
{
|
||||
handle = bgfx::createTextureCube(
|
||||
@@ -226,20 +240,6 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const bx::FilePath& _f
|
||||
const bx::StringView name(_filePath);
|
||||
bgfx::setName(handle, name.getPtr(), name.getLength() );
|
||||
}
|
||||
|
||||
if (NULL != _info)
|
||||
{
|
||||
bgfx::calcTextureSize(
|
||||
*_info
|
||||
, uint16_t(imageContainer->m_width)
|
||||
, uint16_t(imageContainer->m_height)
|
||||
, uint16_t(imageContainer->m_depth)
|
||||
, imageContainer->m_cubeMap
|
||||
, 1 < imageContainer->m_numMips
|
||||
, imageContainer->m_numLayers
|
||||
, bgfx::TextureFormat::Enum(imageContainer->m_format)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user