From 0b1f61b8ceb901f1ad4e26080475a0cf84ea7de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E9=BE=99=E5=B1=B1=E4=BA=BA?= Date: Mon, 29 Aug 2016 02:23:01 -0500 Subject: [PATCH] fix possible crash of label shrinked (#16456) --- cocos/platform/mac/CCDevice-mac.mm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cocos/platform/mac/CCDevice-mac.mm b/cocos/platform/mac/CCDevice-mac.mm index ae84e4ca36..a23f91c52d 100644 --- a/cocos/platform/mac/CCDevice-mac.mm +++ b/cocos/platform/mac/CCDevice-mac.mm @@ -129,6 +129,10 @@ static NSSize _calculateRealSizeForString(NSAttributedString **str, id font, NSS while (actualSize.size.width > constrainSize.width || actualSize.size.height > constrainSize.height) { fontSize = fontSize - 1; + if (fontSize < 0) { + actualSize = CGRectMake(0, 0, 0, 0); + break; + } NSMutableAttributedString *mutableString = [[*str mutableCopy] autorelease]; *str = __attributedStringWithFontSize(mutableString, fontSize); @@ -162,6 +166,10 @@ static NSSize _calculateRealSizeForString(NSAttributedString **str, id font, NSS while (actualSize.size.height > constrainSize.height ||actualSize.size.width > constrainSize.width) { fontSize = fontSize - 1; + if (fontSize < 0) { + actualSize = CGRectMake(0, 0, 0, 0); + break; + } NSMutableAttributedString *mutableString = [[*str mutableCopy] autorelease]; *str = __attributedStringWithFontSize(mutableString, fontSize);