Cclabelttf issue,do cclabelttf->setstring from JNI call,the label will set to black block

I has a project, in game store,user can buy coins use checkout,when the purchase is done,I call C++ function to update the cclabel string to update the coin number,but I found when I do this,the cclabel change to black block,is there something wrong?
Maybe because the main UI thread?Can somebody Help?

:frowning: can somebody help?

We encounter the same problem, we are using cclabelttf to display some text from user input, the scenario is like this:

  1. we use JNI to invoke some java api to input text, invoke java from C*+
  2. when user finish typing, in callback, we use cclabelttf’s setstring to make it display what is input, which invoke C*+ from java

we doubt that due to some reason, in step 1 we guess, when we invoke something like this via JNI, it actually invoke a new thread, in this case, when we call setstring, which means we a doing some renderer relevant work in non-UI thread.

in the end, we fix the bug via only set some flag variable in step 2, check that flag and do the actually setstring in UI thread and it works fine now.

I am trying to figure out how to get back to the UI thread from a JNI call.

I suspect that it may have something to do with CCScheduler but I cannot find the code.

Hi~!!

In cocos2dx, UI Thread is operating. So If you want to call UI thread from Android JNI, You should use a scheduler from Android JNI.

In cocos2d-x ver 2.x.x
for example, use that scheduleOnce(schedule_selector(HelloWorld::functionName), DELAYTIME); in JNI Function.

good luck…