mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
ImFontAtlas: Handle stb_truetype failure more gracefully, GetTexDataAsRGBA32() won't crash during conversion. (#1527)
This commit is contained in:
parent
6ec00a366a
commit
4af84ac781
@ -1439,11 +1439,14 @@ void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_wid
|
|||||||
{
|
{
|
||||||
unsigned char* pixels;
|
unsigned char* pixels;
|
||||||
GetTexDataAsAlpha8(&pixels, NULL, NULL);
|
GetTexDataAsAlpha8(&pixels, NULL, NULL);
|
||||||
TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4));
|
if (pixels)
|
||||||
const unsigned char* src = pixels;
|
{
|
||||||
unsigned int* dst = TexPixelsRGBA32;
|
TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4));
|
||||||
for (int n = TexWidth * TexHeight; n > 0; n--)
|
const unsigned char* src = pixels;
|
||||||
*dst++ = IM_COL32(255, 255, 255, (unsigned int)(*src++));
|
unsigned int* dst = TexPixelsRGBA32;
|
||||||
|
for (int n = TexWidth * TexHeight; n > 0; n--)
|
||||||
|
*dst++ = IM_COL32(255, 255, 255, (unsigned int)(*src++));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*out_pixels = (unsigned char*)TexPixelsRGBA32;
|
*out_pixels = (unsigned char*)TexPixelsRGBA32;
|
||||||
@ -1683,6 +1686,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|||||||
IM_ASSERT(font_offset >= 0);
|
IM_ASSERT(font_offset >= 0);
|
||||||
if (!stbtt_InitFont(&tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset))
|
if (!stbtt_InitFont(&tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset))
|
||||||
{
|
{
|
||||||
|
atlas->TexWidth = atlas->TexHeight = 0; // Reset output on failure
|
||||||
ImGui::MemFree(tmp_array);
|
ImGui::MemFree(tmp_array);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user