CCLabelTTF->setString() crash on Mac OSX

CCLabelTTF->setString() crash on Mac OSX

Hi there,

I’m having some strange problems with the Mac OSX version of Cocos2dx. I’m trying to show a “thank you” message to the user after they have purchased a piece of in-app content. It basically comes down to a call to:

CCLabelTTF *txtLabel = (CCLabelTTF*)loadingContainer->getChildByTag(1); txtLabel->setString("Thank you");

…which works perfectly well throughout the rest of my app. However, in this instance it crashes 100% of the time inside CCTexture2D::initWithData():

glPixelStorei(GL_UNPACK_ALIGNMENT, 8); //Crashes here

Now I’ve seen commits (like this one: which talk about the bit packing being a little messed up. Am I running into something like that on OSX? I somehow don’t think so, as I would see it elsewhere in the app.

My only other guess is that the Mac App Store in-app purchase code is returning on a different thread, and all of my existing references are messed up somehow. Has anybody had any experience in this, or could provide any kind of insight? I really would appreciate the help, as I’m at a bit of a loose end here.

Thanks very much for your time,


Nobody else developing for OS X? It doesn’t seem like it’s a very popular platform on these forums… :frowning:


I ran into the same problem

solution is to run on main thread

dispatch_async(dispatch_get_main_queue(), ^{
CCLabelTTF *txtLabel = (CCLabelTTF*)loadingContainer->getChildByTag(1); txtLabel->setString("Thank you");});

@bilalmirza I responded to this not realising it’s over 6 years old… Best to avoid resurrecting old threads like this, because there it’s more than likely that the engine code has changed a lot in all these years, so questions may no longer be relevant. It’s better to make a new thread.

Anyhow, if you want to access objects like the label, then use this method:

    CCLabelTTF *txtLabel = (CCLabelTTF*)loadingContainer->getChildByTag(1); 
    txtLabel->setString("Thank you");

Sorry, I did saw that it was 6 years old just wanted to give out a solution. I’ll avoid old threads from now on.

@R101 Thanks for the correct answer.