Fixed assert macros, and improved error handling.

This commit is contained in:
Бранимир Караџић
2021-10-25 18:59:32 -07:00
parent 6573fc44a8
commit 8392a44b3a
35 changed files with 705 additions and 617 deletions

View File

@@ -71,7 +71,6 @@ TrueTypeFont::~TrueTypeFont()
bool TrueTypeFont::init(const uint8_t* _buffer, uint32_t _bufferSize, int32_t _fontIndex, uint32_t _pixelHeight, int16_t _widthPadding, int16_t _heightPadding)
{
BX_ASSERT(m_font == NULL, "TrueTypeFont already initialized");
BX_ASSERT( (_bufferSize > 256 && _bufferSize < 100000000), "TrueType buffer size is suspicious");
BX_ASSERT( (_pixelHeight > 4 && _pixelHeight < 128), "TrueType buffer size is suspicious");
BX_UNUSED(_bufferSize);
@@ -89,8 +88,6 @@ bool TrueTypeFont::init(const uint8_t* _buffer, uint32_t _bufferSize, int32_t _f
FontInfo TrueTypeFont::getFontInfo()
{
BX_ASSERT(m_font != NULL, "TrueTypeFont not initialized");
int ascent;
int descent;
int lineGap;
@@ -115,8 +112,6 @@ FontInfo TrueTypeFont::getFontInfo()
bool TrueTypeFont::bakeGlyphAlpha(CodePoint _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer)
{
BX_ASSERT(m_font != NULL, "TrueTypeFont not initialized");
int32_t ascent, descent, lineGap;
stbtt_GetFontVMetrics(&m_font, &ascent, &descent, &lineGap);
@@ -147,8 +142,6 @@ bool TrueTypeFont::bakeGlyphAlpha(CodePoint _codePoint, GlyphInfo& _glyphInfo, u
bool TrueTypeFont::bakeGlyphDistance(CodePoint _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer)
{
BX_ASSERT(m_font != NULL, "TrueTypeFont not initialized");
int32_t ascent, descent, lineGap;
stbtt_GetFontVMetrics(&m_font, &ascent, &descent, &lineGap);
@@ -290,7 +283,7 @@ TrueTypeHandle FontManager::createTtf(const uint8_t* _buffer, uint32_t _size)
void FontManager::destroyTtf(TrueTypeHandle _handle)
{
BX_ASSERT(bgfx::isValid(_handle), "Invalid handle used");
BX_ASSERT(isValid(_handle), "Invalid handle used");
delete m_cachedFiles[_handle.idx].buffer;
m_cachedFiles[_handle.idx].bufferSize = 0;
m_cachedFiles[_handle.idx].buffer = NULL;
@@ -300,7 +293,7 @@ void FontManager::destroyTtf(TrueTypeHandle _handle)
FontHandle FontManager::createFontByPixelSize(TrueTypeHandle _ttfHandle, uint32_t _typefaceIndex, uint32_t _pixelSize, uint32_t _fontType,
uint16_t _glyphWidthPadding, uint16_t _glyphHeightPadding)
{
BX_ASSERT(bgfx::isValid(_ttfHandle), "Invalid handle used");
BX_ASSERT(isValid(_ttfHandle), "Invalid handle used");
TrueTypeFont* ttf = new TrueTypeFont();
if (!ttf->init(m_cachedFiles[_ttfHandle.idx].buffer, m_cachedFiles[_ttfHandle.idx].bufferSize, _typefaceIndex, _pixelSize, _glyphWidthPadding, _glyphHeightPadding) )
@@ -327,7 +320,7 @@ FontHandle FontManager::createFontByPixelSize(TrueTypeHandle _ttfHandle, uint32_
FontHandle FontManager::createScaledFontToPixelSize(FontHandle _baseFontHandle, uint32_t _pixelSize)
{
BX_ASSERT(bgfx::isValid(_baseFontHandle), "Invalid handle used");
BX_ASSERT(isValid(_baseFontHandle), "Invalid handle used");
CachedFont& baseFont = m_cachedFonts[_baseFontHandle.idx];
FontInfo& fontInfo = baseFont.fontInfo;
@@ -356,7 +349,7 @@ FontHandle FontManager::createScaledFontToPixelSize(FontHandle _baseFontHandle,
void FontManager::destroyFont(FontHandle _handle)
{
BX_ASSERT(bgfx::isValid(_handle), "Invalid handle used");
BX_ASSERT(isValid(_handle), "Invalid handle used");
CachedFont& font = m_cachedFonts[_handle.idx];
@@ -372,7 +365,7 @@ void FontManager::destroyFont(FontHandle _handle)
bool FontManager::preloadGlyph(FontHandle _handle, const wchar_t* _string)
{
BX_ASSERT(bgfx::isValid(_handle), "Invalid handle used");
BX_ASSERT(isValid(_handle), "Invalid handle used");
CachedFont& font = m_cachedFonts[_handle.idx];
if (NULL == font.trueTypeFont)
@@ -394,7 +387,7 @@ bool FontManager::preloadGlyph(FontHandle _handle, const wchar_t* _string)
bool FontManager::preloadGlyph(FontHandle _handle, CodePoint _codePoint)
{
BX_ASSERT(bgfx::isValid(_handle), "Invalid handle used");
BX_ASSERT(isValid(_handle), "Invalid handle used");
CachedFont& font = m_cachedFonts[_handle.idx];
FontInfo& fontInfo = font.fontInfo;
@@ -472,7 +465,7 @@ bool FontManager::preloadGlyph(FontHandle _handle, CodePoint _codePoint)
bool FontManager::addGlyphBitmap(FontHandle _handle, CodePoint _codePoint, uint16_t _width, uint16_t _height, uint16_t _pitch, float extraScale, const uint8_t* _bitmapBuffer, float glyphOffsetX, float glyphOffsetY)
{
BX_ASSERT(bgfx::isValid(_handle), "Invalid handle used");
BX_ASSERT(isValid(_handle), "Invalid handle used");
CachedFont& font = m_cachedFonts[_handle.idx];
GlyphHashMap::iterator iter = font.cachedGlyphs.find(_codePoint);
@@ -519,7 +512,7 @@ bool FontManager::addGlyphBitmap(FontHandle _handle, CodePoint _codePoint, uint1
const FontInfo& FontManager::getFontInfo(FontHandle _handle) const
{
BX_ASSERT(bgfx::isValid(_handle), "Invalid handle used");
BX_ASSERT(isValid(_handle), "Invalid handle used");
return m_cachedFonts[_handle.idx].fontInfo;
}