From 10b71464a792963c51463f72478f7bd51a5e5cf0 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Tue, 5 May 2015 17:17:41 -0700 Subject: [PATCH] No throws in cocos2d-x code --- cocos/2d/MarchingSquare.cpp | 12 +++++---- .../allocator/CCAllocatorGlobalNewDelete.cpp | 26 ++++++++++++------- .../cocostudio/ActionTimeline/CCFrame.cpp | 18 +++---------- tests/cpp-tests/Classes/controller.cpp | 2 +- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/cocos/2d/MarchingSquare.cpp b/cocos/2d/MarchingSquare.cpp index ba4a479d92..773e51e7e8 100644 --- a/cocos/2d/MarchingSquare.cpp +++ b/cocos/2d/MarchingSquare.cpp @@ -61,7 +61,7 @@ unsigned int MarchingSquare::findFirstNoneTransparentPixel() return i; } } - throw "image is all transparent!"; + CCASSERT(false, "image is all transparent!"); } unsigned char MarchingSquare::getAlphaAt(const unsigned int i) @@ -235,10 +235,13 @@ void MarchingSquare::marchSquare(int startx, int starty) break; case 0: CCLOG("case 0 at x:%d, y:%d, coming from %d, %d", curx, cury, prevx, prevy); - throw "this shoudln't happen"; + CCASSERT(false, "this shoudln't happen"); + break; case 15: CCLOG("case 15 at x:%d, y:%d, coming from %d, %d", curx, cury, prevx, prevy); - throw "this shoudln't happen"; + CCASSERT(false, "this shoudln't happen"); + break; + } //little optimization // if previous direction is same as current direction, @@ -266,8 +269,7 @@ void MarchingSquare::marchSquare(int startx, int starty) prevx = stepx; prevy = stepy; problem = false; - if(count > totalPixel) - throw "oh no, marching square cannot find starting position"; + CCASSERT(count <= totalPixel, "oh no, marching square cannot find starting position"); } while(curx != startx || cury != starty); } diff --git a/cocos/base/allocator/CCAllocatorGlobalNewDelete.cpp b/cocos/base/allocator/CCAllocatorGlobalNewDelete.cpp index 72098a1375..b53d6bb864 100644 --- a/cocos/base/allocator/CCAllocatorGlobalNewDelete.cpp +++ b/cocos/base/allocator/CCAllocatorGlobalNewDelete.cpp @@ -28,6 +28,8 @@ #include #include +#include "base/ccMacros.h" + USING_NS_CC_ALLOCATOR; #if CC_ENABLE_ALLOCATOR @@ -43,21 +45,27 @@ namespace void* operator new[] (std::size_t size) { void* ptr = global.allocate(size); -#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID - if (nullptr == ptr) - throw std::bad_alloc(); -#endif - return ptr; + CCASSERT(ptr, "No memory"); + + // dissabling exceptions since cocos2d-x doesn't use them +//#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID +// if (nullptr == ptr) +// throw std::bad_alloc(); +//#endif + return ptr; } // @brief overrides global operator new void* operator new(std::size_t size) { void* ptr = global.allocate(size); -#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID - if (nullptr == ptr) - throw std::bad_alloc(); -#endif + CCASSERT(ptr, "No memory"); + + // dissabling exceptions since cocos2d-x doesn't use them +//#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID +// if (nullptr == ptr) +// throw std::bad_alloc(); +//#endif return ptr; } diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp index 69b618418c..e102894f8e 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp @@ -606,32 +606,20 @@ void InnerActionFrame::onEnter(Frame *nextFrame, int currentFrameIndex) void InnerActionFrame::setStartFrameIndex(int frameIndex) { - if(_enterWithName) - { - CCLOG(" cannot set start when enter frame with name. setEnterWithName false firstly!"); - throw std::exception(); - } + CCASSERT(_enterWithName, " cannot setStartFrameIndex when enterWithName is set"); _startFrameIndex = frameIndex; } void InnerActionFrame::setEndFrameIndex(int frameIndex) { - if(_enterWithName) - { - CCLOG(" cannot set end when enter frame with name. setEnterWithName false firstly!"); - throw std::exception(); - } + CCASSERT(_enterWithName, " cannot setEndFrameIndex when enterWithName is set"); _endFrameIndex = frameIndex; } void InnerActionFrame::setAnimationName(const std::string& animationName) { - if(!_enterWithName) - { - CCLOG(" cannot set aniamtioname when enter frame with index. setEnterWithName true firstly!"); - throw std::exception(); - } + CCASSERT(!_enterWithName, " cannot set aniamtioname when enter frame with index. setEnterWithName true firstly!"); _animationName = animationName; } diff --git a/tests/cpp-tests/Classes/controller.cpp b/tests/cpp-tests/Classes/controller.cpp index e93ff92890..410b7556f7 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -16,7 +16,6 @@ class RootTests : public TestList public: RootTests() { - addTest("SpritePolygon", [](){return new (std::nothrow) SpritePolygonTest(); }); addTest("ActionManager", [](){return new (std::nothrow) ActionManagerTests(); }); addTest("Actions - Basic", [](){ return new (std::nothrow) ActionsTests(); }); addTest("Actions - Ease", [](){return new (std::nothrow) ActionsEaseTests(); }); @@ -66,6 +65,7 @@ public: addTest("Node: Spine", [](){return new SpineTests(); }); addTest("Node: Sprite", [](){return new SpriteTests(); }); addTest("Node: Sprite3D", [](){ return new Sprite3DTests(); }); + addTest("Node: SpritePolygon", [](){return new (std::nothrow) SpritePolygonTest(); }); addTest("Node: Terrain", [](){ return new TerrainTests(); }); addTest("Node: TileMap", [](){return new TileMapTests(); }); addTest("Node: FastTileMap", [](){return new FastTileMapTests(); });