I am just writing a Tetris game by myself, I finish it on Visual Studio 2010 and get it running well on Windows 7, but when I cross-compile the code to Android platform in form of native .so file and try to get it run on Android 4.0.3, The game crash right after start-up, I look back to my C++ code and find the problem being caused by the code below:
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
TetrisGame tGame(20,10); //this sentence cause the problem
return scene;
}
function scene is a static fucntion of HelloWorld ,which is a subclass of CCLayer, TetrisGame is a custom class.
When I declare a local object of TetrisGame in function scene() just like the code above, the game crash on start-up.(On windows 7, the same code runs well:) )
The error message is :
I modify the sentence to dynamic create like below,the game crash on start-up as before:
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
TetrisGame * tGame=new TetrisGame(20,10); //this sentence cause the problem
return scene;
}
But the error message is just below:
TetrisGame is a class without any dependence on cocos2d,it is defined below:
class TetrisGame
{
public:
TetrisGame(int row=0,int col=0,int colorCount=7,int speed=1);
void reset();
ShapeInfo & getCurrentShapeInfo();
void run();
void receiveCommand(Command cmd);
short ** getBoardPointer();
~TetrisGame(void);
void (* rushingBeginHandler)();
void (* rushingEndHandler)();
void (* gameOverHandler)();
bool levelUp();
bool setLevel(int i);
int getLevel();
long int getScore();
private:
int row,col;
short ** pBoard;
int colorCount;
int level;//当前等级
long int score;//当前得分
static const int rushSpeed;
ShapeInfo currentShapeInfo;
GameState currentState;
int startX;
int startY;
int speed;
void generateNewShape();
bool checkCollision(int x,int y,int pose);
void putCurrentShape();
void clearCurrentShape();
void clearFullRows();
bool checkRowFull(int rowIndex);
};
Its constructor is implememted as below:
TetrisGame::TetrisGame(int row,int col,int colorCount,int speed)
{
this->row=row;this->col=col;
startX=3;
startY=col/2-2;
this->colorCount=colorCount;
this->speed=speed;
this->rushingBeginHandler=NULL;
this->rushingEndHandler=NULL;
this->gameOverHandler=NULL;
this->pBoard=new short*[row];
for(int i=0;ipBoard[i]=new short[col];
}
for(int i=0;icurrentState=READY;
srand((unsigned)time(NULL));
}
Who can tell me what is the cause of such a strange crash on start-up at Android 4.0.3(PS: The same code runs well on Windows 7 32_bit), thanks for any help:)
error.png (10.2 KB)
error.png (10.2 KB)
error2.png (2.5 KB)