瀏覽代碼

Security check in case of not valid font

Ray 4 年之前
父節點
當前提交
2015828fc6
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      src/text.c

+ 4 - 2
src/text.c

@@ -848,12 +848,14 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
 // NOTE: chars spacing is NOT proportional to fontSize
 void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
 {
-    int length = TextLength(text);      // Total length in bytes of the text, scanned by codepoints in loop
+    if (font.texture.id == 0) font = GetFontDefault();  // Security check in case of not valid font
+    
+    int length = TextLength(text);  // Total length in bytes of the text, scanned by codepoints in loop
 
     int textOffsetY = 0;            // Offset between lines (on line break '\n')
     float textOffsetX = 0.0f;       // Offset X to next character to draw
 
-    float scaleFactor = fontSize/font.baseSize;     // Character quad scaling factor
+    float scaleFactor = fontSize/font.baseSize;         // Character quad scaling factor
 
     for (int i = 0; i < length;)
     {