Hello all,
Well, I’m back with another Android issue. This time it’s a real weird one. Unfortunately, I am able to get a crash dump as I’m compiling on a Mac straight out of terminal. If there’s any good independent log tracking program for Droid I would be happy to know of that as well (Eclipse doesn’t seem to work giving very generic error).
As part of our app, we have a Memory game, you know for kids. It’s a very simple game that generates a grid of a Card Object (inheriting from Node) and then keeps track of matches for each player. It works flawlessly on iOS, and on Droid it works perfectly as long as you choose one of the three lower Card count settings. Once you choose 30 or 42, you get an “Unfortunately [App Name] has stopped working.” Error. The really weird part is that if you go to recent apps and click on it, it goes into the game and the game works perfectly fine from there (However if you try to relaunch it or replay with that card count it will hard crash).
Well, I’ve been banging my head against it for a couple of days and can’t seem to figure out what Droid is having a problem with. I couldn’t find anything about object creation limitations in Droid by searching Google. So I come to you, mighty Cocos2dx power users, please take a look at the following code and let me know where I’m going wrong:
bool PMCardGrid::buildCardGrid(){
//Possible Cards vector populating
this->possCards = {/load the vector with 24 card names/};
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("PMcards.plist"); //Sprite sheet for the cards
vector<Vec2> origins = vector<Vec2>(); origins = this->getCardConfiguration(); //Function gets all positions to organize the cards into as close to a square as possible
this->cards = Vector<PMCard*>();
const int numPairs = this->totalCards / 2; //Pairs is equal to half of total cards, total cards options cap out at 42, but both 30 and 42 crash
for(int i(0); i != numPairs; i++){
int index1 = 0;
if(origins.size() > 1){ index1 = SceneManager::getRandomIntInRange(0, (int)origins.size() - 1); //Function for getting a random int in range inclusive }
Vec2 point1 = origins.at(index1);
origins.erase(origins.begin() + index1);
int index2 = 0;
if(origins.size() > 1){ index2 = SceneManager::getRandomIntInRange(0, (int)origins.size() - 1); }
Vec2 point2 = origins.at(index2);
origins.erase(origins.begin() + index2);
if(!this->addCard(point1, point2)){ //This add card function included below. Made boolean to make sure it wasn't failing break; }
}
return true;}
bool PMCardGrid::addCard(Vec2 point1, Vec2 point2){
int indexRand = 0;
if(possCards.size() > 1){ indexRand = SceneManager::getRandomIntInRange(0, (int)possCards.size() - 1); }
string cardName = possCards.at(indexRand);
auto card1 = PMCard::create(this->cardSize, cardName); card1->setPosition(point1); this->addChild(card1, 5);
auto card2 = PMCard::create(this->cardSize, cardName); card2->setPosition(point2); this->addChild(card2, 5);
if(card1 != NULL && card2 != NULL){ cards.pushBack(card1); cards.pushBack(card2);
possCards.erase(possCards.begin() + indexRand); return true; }
return false;}