Blackberry CCSprite::create doesn't work as expected

I’m having a problem with centering a jpeg on Blackberry. I have the code below:

`bool MyScene::init() {

if ( !CCLayer::init() ) {
    return false;
}

CCSize size = CCDirector::sharedDirector()->getWinSize();

bg = CCSprite::create("2.jpg");
bg->setPosition(ccp( size.width/2 , size.height/2 ));
this->addChild(bg); 

fg = CCSprite::create("hud2.png");
fg->setPosition(ccp( size.width/2 , 25 ));
this->addChild(fg);

fg2 = CCSprite::create("hud.png");
fg2->setPosition(ccp( size.width/2 , size.height - 30 ));
this->addChild(fg2);

std::stringstream stream;
stream << "size is " << (size.width/2) << "and " (size.height/2);
std::string outtext = stream.str();

label = CCLabelTTF::create(outtext.c_str(), "DejaVuSansMono.ttf", 25, CCSizeMake(size.width, 25), kCCTextAlignmentCenter);
label->setPosition(ccp( size.width/2 , 28 ));
this->addChild(label);

}`

If I run that, the label will print out that size is 0 and the jpeg is in the lower left corner instead of centered in the middle. However, if I load a png instead of the jpeg, everything works fine. To further confuse me, if I move the code that fills the string with the values of ‘size’ to right under the code that sets ‘size’, everything works fine. If I put that code anywhere else, or take it out completely, ‘size’ (presumably) goes back to 0 and the jpeg doesn’t get centered. This problem only happens on Blackberry, but it seems like ‘size’ is getting set correctly so I don’t know that it is a cocos2d-x bug. Could there be some compiler kookiness messing things up or just some really simple error I’m missing that other compilers are more forgiving for?

I have some more information that may be helpful, although it just confuses me more. The above code is in the second scene of the app, the first is a splash screen. JPGs work fine in the splash screen. And if I load the jpg from the splash screen in the code above, everything works fine.

I even replaced the line that sets the position to this:

bg->setPosition(ccp( CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height/2 ));

And the image still appears in the bottom left of the screen. Again, PNGs work fine and the problem only happens on the device, not the simulator.

I have another game, in that one, the jpg background on the first and second scenes work fine. But the one on the third scene doesn’t. That one creates the background in a second function that is called from the init() function. In that one, even if I set the coordinates manually, the image doesn’t display right. It is centered vertically correctly, but not horizontally.

To me, it seems like a memory issue, like something is getting overwritten that shouldn’t be. But I have no idea how to track that down.

I’ve figured out the problem, but have no clue how to fix it. If I create my sprite by using the texture cache, like so:

@ CCTexture2D *paddleTexture = CCTextureCache::sharedTextureCache()>addImage;
bg = new CCSprite;
bg
>initWithTexture(paddleTexture);@

Then everything works as expected. But if I use CCSprite::create(), it doesn’t. I have no idea why this would be happening, since CCSprite::create just calls the exact same functions that work without it. I even tried copying and pasting the initwithtexture code into the create function so it didn’t have to call anything, and it still doesn’t work. Again, the problem only exists with jpgs, not pngs. Does anyone have any idea how to fix this?