No throws in cocos2d-x code

This commit is contained in:
Ricardo Quesada 2015-05-05 17:17:41 -07:00
parent e52ca38619
commit 10b71464a7
4 changed files with 28 additions and 30 deletions

View File

@ -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);
}

View File

@ -28,6 +28,8 @@
#include <new>
#include <exception>
#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;
}

View File

@ -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;
}

View File

@ -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(); });