Skip to content

Commit 21b1d47

Browse files
committed
Few bugs discovered by build on recent Clang and few logical bugs discovered before
1 parent bb9b30a commit 21b1d47

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

cocos/2d/CCFontAtlas.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ FontAtlas::~FontAtlas()
129129
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
130130
if (_iconv)
131131
{
132-
iconv_close(_iconv);
132+
iconv_close((iconv_t)_iconv);
133133
_iconv = nullptr;
134134
}
135135
#endif
@@ -262,7 +262,7 @@ void FontAtlas::conversionU32TOGB2312(const std::u32string& u32Text, std::unorde
262262
size_t inLen = strLen * 2;
263263
size_t outLen = gb2312StrSize;
264264

265-
iconv(_iconv, (char**)&pin, &inLen, &pout, &outLen);
265+
iconv((iconv_t)_iconv, (char**)&pin, &inLen, &pout, &outLen);
266266
}
267267
#endif
268268
}

cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public static int getIntegerForKey(String key, int defaultValue) {
468468
Map allValues = settings.getAll();
469469
Object value = allValues.get(key);
470470
if ( value instanceof String) {
471-
return Integer.parseInt(value.toString());
471+
try { return Integer.parseInt(value.toString()); } catch (Exception e) { return 0; }
472472
}
473473
else if (value instanceof Float)
474474
{
@@ -496,7 +496,7 @@ public static float getFloatForKey(String key, float defaultValue) {
496496
Map allValues = settings.getAll();
497497
Object value = allValues.get(key);
498498
if ( value instanceof String) {
499-
return Float.parseFloat(value.toString());
499+
try { return Float.parseFloat(value.toString()); } catch (Exception e) { return 0.0f; }
500500
}
501501
else if (value instanceof Integer)
502502
{

cocos/renderer/CCTexture2D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Texture2D::~Texture2D()
151151
#endif
152152
CC_SAFE_RELEASE_NULL(_alphaTexture); // ETC1 ALPHA support.
153153

154-
CCLOGINFO("deallocing Texture2D: %p - id=%u", this, _name);
154+
CCLOGINFO("deallocing Texture2D: %p - id=%u", this, /*_name*/0);
155155

156156
CC_SAFE_DELETE(_ninePatchInfo);
157157

cocos/ui/UILayoutManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void LinearHorizontalLayoutManager::doLayout(LayoutProtocol* layout)
5959
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
6060
Vec2 ap = child->getAnchorPoint();
6161
Size cs = child->getBoundingBox().size;
62+
Margin mg = layoutParameter->getMargin();
6263
float finalPosX = leftBoundary + (ap.x * cs.width);
6364
float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height;
6465
switch (childGravity)
@@ -67,15 +68,14 @@ void LinearHorizontalLayoutManager::doLayout(LayoutProtocol* layout)
6768
case LinearLayoutParameter::LinearGravity::TOP:
6869
break;
6970
case LinearLayoutParameter::LinearGravity::BOTTOM:
70-
finalPosY = ap.y * cs.height;
71+
finalPosY = ap.y * cs.height + mg.top; // Add top margin to counter having it subtracted below from finalPosY
7172
break;
7273
case LinearLayoutParameter::LinearGravity::CENTER_VERTICAL:
73-
finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y);
74+
finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y) + mg.top; // Add top margin to counter having it subtracted below from finalPosY
7475
break;
7576
default:
7677
break;
7778
}
78-
Margin mg = layoutParameter->getMargin();
7979
finalPosX += mg.left;
8080
finalPosY -= mg.top;
8181
child->setPosition(Vec2(finalPosX, finalPosY));
@@ -117,6 +117,7 @@ void LinearVerticalLayoutManager::doLayout(LayoutProtocol* layout)
117117
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
118118
Vec2 ap = subWidget->getAnchorPoint();
119119
Size cs = subWidget->getBoundingBox().size;
120+
Margin mg = layoutParameter->getMargin();
120121
float finalPosX = ap.x * cs.width;
121122
float finalPosY = topBoundary - ((1.0f-ap.y) * cs.height);
122123
switch (childGravity)
@@ -125,15 +126,14 @@ void LinearVerticalLayoutManager::doLayout(LayoutProtocol* layout)
125126
case LinearLayoutParameter::LinearGravity::LEFT:
126127
break;
127128
case LinearLayoutParameter::LinearGravity::RIGHT:
128-
finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
129+
finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width) - mg.left; // Subtract left margin to counter having it added below to finalPosX
129130
break;
130131
case LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL:
131-
finalPosX = layoutSize.width / 2.0f - cs.width * (0.5f-ap.x);
132+
finalPosX = layoutSize.width / 2.0f - cs.width * (0.5f-ap.x) - mg.left; // Subtract left margin to counter having it added below to finalPosX
132133
break;
133134
default:
134135
break;
135136
}
136-
Margin mg = layoutParameter->getMargin();
137137
finalPosX += mg.left;
138138
finalPosY -= mg.top;
139139
subWidget->setPosition(finalPosX, finalPosY);

cocos/ui/UIScrollView.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void ScrollView::setInnerContainerPosition(const Vec2 &position)
233233
// Process bouncing events
234234
if(_bounceEnabled)
235235
{
236-
for(int direction = (int) MoveDirection::TOP; direction < (int) MoveDirection::RIGHT; ++direction)
236+
for(int direction = (int) MoveDirection::TOP; direction <= (int) MoveDirection::RIGHT; ++direction)
237237
{
238238
if(isOutOfBoundary((MoveDirection) direction))
239239
{

0 commit comments

Comments
 (0)