Crash in Nexus 5 with Android 5.0.1

Thanks both for your answers.

I tested on a Moto G with Android 5.0.1 and it works well, so I guess that it’s not an NDK/target-build issue. It’s true that I set the APP_PLATFORM in Application.mk to android-19, but I do this because of what I read here and here: if I set APP_PLATFORM to android-21, given that some functions from stdlib.h changed (inline issues), the game wouldn’t run android versions below 5. However, according to those links, setting APP_PLATFORM to android-19 should allow executing the game on Android 5 and below. (I’m using NDK r10d x86_64, which I assume to have the same problem as NDK r10c).

I’m almost sure that there shouldn’t be a problem with the play button code, which it’s pretty standard. In the init method:

mPlayButton = MenuItemImage::create("playMenu.png", "playMenu.png",     CC_CALLBACK_0(MenuScreen::ToNewGame, this));
mPlayButton -> setPosition(Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2));
this -> addChild(mPlayButton);

The listener:

 listener -> onTouchEnded = [=](Touch* touch, Event* event)  {
    
    Vec2 location = touch -> getLocation();
    if ( mPlayButton -> getBoundingBox().containsPoint(location) )
    {
        mPlayButton -> activate();
    }

And finally, the selector:

void MenuScreen::ToNewGame()
{
    if ( !ConfigManager::GetInstance() -> NoAdsPurchased() )
    {
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
        AdBannerC::GetInstance() -> hideBannerView();
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
        AdmobHelper::HideAd();
#endif
    }
Director::getInstance() -> replaceScene(TransitionCrossFade::create(1.0f, GameManager::CreateScene()));
}

The only “weird” code here is that depending on the system (Android or iOS), I use one or another way to hide the advertisement banner during the main game, but this is also pretty tested and it seems to work fine. In Android, the AdmobHelper is simply an utility class that under the hood calls a static Java method through JNI, which in turn hides the banner (running the action on the UI thread). I debugged and tested this, and it works fine.

I forgot to explain in my first post that the game also crashes when the player, instead of tapping the play button, taps the credits button (which leads to another screen where the credits information is shown). So, it seems that the problem arises when a screen transition/change is taking place. In the case of the credits screen selector, I simply call replaceScene; I don’t do anything about the banner (the credits screen should display the ad banner as well).

EDIT: I’m going to check the labels, because as you pointed out, there might be a hidden problem there. Up to now, this is what I have concerning labels in the init() method of GameManager (which seems to be the point of interruption):

std::stringstream ss1;
ss1 << points;
std::string totalPoints( LocalizationManager::GetInstance() -> getLocalizedString( "Total" ) + ": " + ss1.str());
totalPointsLabel = Label::createWithTTF(totalPoints, "fonts/GILSANUB.TTF", ConfigManager::GetInstance() -> GetFontSizeForPoints() );
totalPointsLabel -> setPosition(Vec2(origin.x + visibleSize.width / 2,
                                      origin.y + visibleSize.height - totalPointsLabel->getContentSize().height));
this->addChild(totalPointsLabel, 1);

std::stringstream ss2;
ss2 << best;
std::string bestPoints( LocalizationManager::GetInstance() -> getLocalizedString( "Best" ) + ": " + ss2.str());
bestPointsLabel = Label::createWithTTF(bestPoints, "fonts/GILSANUB.TTF", ConfigManager::GetInstance() -> GetFontSizeForPoints() );
bestPointsLabel -> setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - totalPointsLabel -> getContentSize().height * 2));
this->addChild(bestPointsLabel, 1);

std::stringstream ss3;
ss3 << lives;
std::string totalLives("x" + ss3.str());
livesLabel = Label::createWithTTF(totalLives, "fonts/GILSANUB.TTF", ConfigManager::GetInstance() -> GetFontSizeForPoints() );
livesLabel -> setPosition(Vec2(origin.x + visibleSize.width - livesLabel -> getContentSize().width / 2,
                                origin.y + visibleSize.height - livesLabel -> getContentSize().height));
this -> addChild(livesSprite);

Variables “lives” and “points” are initialized just right before:

lives = totalLives; //totalLives being a static const defined in the header
points = 0;

“best”, on the other hand, is retrieved from cocos2d::UserDefault:

best =  cocos2d::UserDefault::getInstance() -> getIntegerForKey( "best" );

The thing is that I declare “best” as uint64_t, but getIntegerForKey returns an int, so maybe the error is there. I’ll test it by simply changing the definition of best to best = 0.