瀏覽代碼

Fix textSize null case

nockawa 9 年之前
父節點
當前提交
21f6b85767
共有 1 個文件被更改,包括 10 次插入6 次删除
  1. 10 6
      src/Canvas2d/babylon.text2d.ts

+ 10 - 6
src/Canvas2d/babylon.text2d.ts

@@ -178,13 +178,17 @@
         }
 
         public get textSize(): Size {
-            if (!this._textSize && this.owner) {
-                let newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
-                if (!newSize.equals(this._textSize)) {
-                    this.onPrimitivePropertyDirty(Prim2DBase.sizeProperty.flagId);
-                    this._positioningDirty();
+            if (!this._textSize) {
+                if (this.owner) {
+                    let newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
+                    if (!newSize.equals(this._textSize)) {
+                        this.onPrimitivePropertyDirty(Prim2DBase.sizeProperty.flagId);
+                        this._positioningDirty();
+                    }
+                    this._textSize = newSize;
+                } else {
+                    return Text2D.nullSize;
                 }
-                this._textSize = newSize;
             }
             
             return this._textSize;