app goes in background at startup

app goes in background at startup
0.0 0


Hello I’m working on my first cocos2d-x project and I have problem which I wasn’t able to google
my application works just fine on windows ( compiled in VS2010 )
but when I test it on my nexus 4 black screen appears for a second and then app goes to background
if I try to activate app it does same thing again
so no error message appears at all

code is too big to post here but I’ll highlight what basically I’m doing
I have sprites in my Resources folder
also I’m using rapidjson to load map ( json file also located in Resources )
I’m doing some sprite loading and touch event handling that’s all
and I have added -std=gnu0x in to use c11 lambda functions

if you have any idea what might be causing this problem or how can I debug this please help


I did further investigation and it seams that problem is caused by this method

std::vector* LevelLoader::GetSprites()
    CCSprite* sprite;
    if( this->sprites != NULL ) return this->sprites;

    this->sprites = new std::vector();

    rapidjson::Document d;
    d.Parse<0>( this->LevelJson.c_str() );

    for( int i = 0; i < d["Sprites"].Size(); i++ )
        assert( d["Sprites"].IsArray() );
        std::string file = this->Dir + d["Sprites"][i]["file"].GetString();
        sprite = CCSprite::create( file.c_str() );
        int x = d["Sprites"][i]["x"].GetInt();
        int y = 500 - d["Sprites"][i]["y"].GetInt();

        sprite->setAnchorPoint( ccp(0,0) );
        sprite->setPosition( ccp(x,y) );
        this->sprites->push_back( sprite );

    return this->sprites;


problem was that I was loading file like this

std::ifstream in( path, std::ios::in );
std::string contents;
in.seekg(0, std::ios::end);
in.seekg(0, std::ios::beg);[0], contents.size());

I just switched to cocos2d-x loading

unsigned long fileSize;
unsigned char* contents;
contents = CCFileUtils::sharedFileUtils()->getFileData( path.c_str(), "r", &fileSize );

and that solved problem