瀏覽代碼

fix crash if video view doesn't have a size yet

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Florent Pillet 11 年之前
父節點
當前提交
fad3de5d7a
共有 1 個文件被更改,包括 10 次插入8 次删除
  1. 10 8
      Sources/VLCVideoCommon.m

+ 10 - 8
Sources/VLCVideoCommon.m

@@ -48,15 +48,17 @@
         CGRect bounds = layer.bounds;
         CGRect videoRect = bounds;
 
-        CGFloat xRatio = CGRectGetWidth(bounds)/originalVideoSize.width;
-        CGFloat yRatio = CGRectGetHeight(bounds)/originalVideoSize.height;
-        CGFloat ratio = fillScreenEntirely ? MAX(xRatio, yRatio) : MIN(xRatio, yRatio);
-
-        videoRect.size.width = ratio*originalVideoSize.width;
-        videoRect.size.height = ratio*originalVideoSize.height;
-        videoRect.origin.x += (CGRectGetWidth(bounds) - CGRectGetWidth(videoRect))/2.0;
-        videoRect.origin.y += (CGRectGetHeight(bounds) - CGRectGetHeight(videoRect))/2.0;
+        if (originalVideoSize.height > 0 && originalVideoSize.width > 0)
+        {
+            CGFloat xRatio = CGRectGetWidth(bounds) / originalVideoSize.width;
+            CGFloat yRatio = CGRectGetHeight(bounds) / originalVideoSize.height;
+            CGFloat ratio = fillScreenEntirely ? MAX(xRatio, yRatio) : MIN(xRatio, yRatio);
 
+            videoRect.size.width = ratio * originalVideoSize.width;
+            videoRect.size.height = ratio * originalVideoSize.height;
+            videoRect.origin.x += (CGRectGetWidth(bounds) - CGRectGetWidth(videoRect)) / 2.0;
+            videoRect.origin.y += (CGRectGetHeight(bounds) - CGRectGetHeight(videoRect)) / 2.0;
+        }
         videolayer.frame = videoRect;
     }
 }