From 00548b325a7215e0b654f78bf7be9ec7040e37f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 27 May 2015 21:18:43 -0700 Subject: [PATCH] Fixed crash when loading invalid texture. --- examples/common/bgfx_utils.cpp | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/examples/common/bgfx_utils.cpp b/examples/common/bgfx_utils.cpp index 5f19524e..1e4e9024 100644 --- a/examples/common/bgfx_utils.cpp +++ b/examples/common/bgfx_utils.cpp @@ -176,24 +176,27 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uin BX_FREE(allocator, data); - handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), 1 - , bgfx::TextureFormat::RGBA8 - , _flags - , bgfx::copy(img, width*height*4) - ); - - free(img); - - if (NULL != _info) + if (NULL != img) { - bgfx::calcTextureSize(*_info - , uint16_t(width) - , uint16_t(height) - , 0 - , false - , 1 - , bgfx::TextureFormat::RGBA8 - ); + handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), 1 + , bgfx::TextureFormat::RGBA8 + , _flags + , bgfx::copy(img, width*height*4) + ); + + free(img); + + if (NULL != _info) + { + bgfx::calcTextureSize(*_info + , uint16_t(width) + , uint16_t(height) + , 0 + , false + , 1 + , bgfx::TextureFormat::RGBA8 + ); + } } } else