Repository: cocos2d/cocos2d-x

Issue #20622: Some ui::Text components which use UTF-8 strings aren't being rendered. FIXED with both #20000 and #20476 (Issue related to cocos2d::ui::Label::update(), cocos2d::ui::Label::BatchCommand and cocos2d::CustomCommand).
Created: 2020-12-04T09:15:51Z
cocos2d-x version: cocos2d-x-4.0
devices test on: Samsung Galaxy S7 (Oreo 8.0.0)
developing environments

NDK version: 21.3.6528147
Xcode version:N/A
VS version:N/A
browser type and version:N/A



This issue was resolved by implementing the fixes in both #20000 and #20476
I had a cocos2d::Scene which had a number of ui::Text components. If the ui::Text components were initialised without any UTF-8 characters, they appeared to be rendered without issue.
However, if they were initialised with UTF-8 characters, some were rendered and some weren't. After running the adb with the jni debugger, I didn't find any helpful error messages.
Here's some sample code and results before I implemented the fixes:

using namespace cocos2d;

Scene* MainMenuScene::createScene()
{
    return MainMenuScene::create();
}

bool MainMenuScene::init()
{
    if ( !Scene::init() )
    {
        return false;
    }

 auto visibleSize = Director::getInstance()->getVisibleSize();

auto font = "fonts/rounded-mgenplus-1c-black.ttf";
auto font_size = 24;
//HACK: Just used this for quick and dirty spacing
auto kyuu_h = ui::Text::create(u8"きゅう", "fonts/rounded-mgenplus-1c-black.ttf", 24);

    auto layout_kan = ui::Layout::create();
    layout_kan->setLayoutType(ui::Layout::Type::VERTICAL);
    layout_kan->setContentSize(Size(2 * kyuu_h->getContentSize().width, visibleSize.height));

std::vector<std::string> kanji_numbers {u8"一", u8"二", u8"三", u8"四", u8"五",u8"六", u8"七", u8"八", u8"九"};

for (auto num : kanji_numbers) {
    auto label = ui::Text::create(num, font, font_size);
    layout_kan->addChild(label);
}

    auto layout_h = ui::Layout::create();
    layout_h->setLayoutType(ui::Layout::Type::VERTICAL);
    layout_h->setContentSize(Size(2 * kyuu_h->getContentSize().width, visibleSize.height));

std::vector<std::string> hiragana_numbers {u8"いち", u8"に", u8"さん", u8"よん", u8"ご",u8"ろく", u8"なな", u8"はち", u8"きゅう"};

for (auto num : hiragana_numbers) {
    auto label = ui::Text::create(num, font, font_size);
    layout_h->addChild(label);
}

    auto layout_k = ui::Layout::create();
    layout_k->setLayoutType(ui::Layout::Type::VERTICAL);
    layout_k->setContentSize(Size(2 * kyuu_h->getContentSize().width, visibleSize.height));

std::vector<std::string> katakana_numbers {u8"イチ", u8"ニ", u8"サン", u8"ヨン", u8"ゴ",u8"ロク", u8"ナナ", u8"ハチ", u8"キュウ"};

for (auto num : katakana_numbers) {
    auto label = ui::Text::create(num, font, font_size);
    layout_k->addChild(label);
}
    auto layout = ui::Layout::create();
    layout->setLayoutType(ui::Layout::Type::HORIZONTAL);
    layout->setPosition(Vec2(0, visibleSize.height));
    layout->addChild(layout_kan);
    layout->addChild(layout_h);
    layout->addChild(layout_k);

    this->addChild(layout);

    return true;
} 


Here's what that looked like on win32:

Here's what that looked like on android:

The order of instantiation of the ui::Text components appeared to affect how many of them were rendered and prioritisation for rendering appeared to depend on the order of instantiation. However, occasionally a later instantiated ui::Text was displayed when those instantiated before it weren't.
Here's what happened when I instantiated the same ui::Text components in a different order (as above except Kanji, then Katakana, then Hiragana) on android:

Other information:

Increasing the amount of other ui components appeared to decrease the amount of UTF-8 initialised ui::Text components which were rendered.
The ui:Text components which were rendered and those which weren't appeared to remain consistent for a set block of code. In other words, the GUI output doesn't seem to vary with the same code on different runs.
ui::Text components which didn't use UTF-8 strings seem not to be affected and were always displayed.
Removing the u8 prefix from the strings gave the same results on android (missing components but those which were rendered were shown as expected) and led to characters being represented by ???'s on win32.
When compiled on win32 there was no such issue and all ui::Text components were displayed regardless of which character set was used.
Japanese characters were used in testing (including kanji, hiragana and katakana) but presumably this is an issue for all UTF-8 characters.

This issue was resolved by implementing the fixes in both #20000 and #20476

Duplicate issue #20599: a bug in Label
Created: 2020-10-17T09:36:55Z
cocos2d-x/cocos/2d/CCLabel.cpp
    
    
        Lines 1898 to 1902
      in
      c78c58e
    
  
  
    

        
          
           if (_batchCommands.size() != _batchNodes.size()) 
        

        
          
           { 
        

        
          
               _batchCommands.resize(_batchNodes.size()); 
        

        
          
               updateShaderProgram(); 
        

        
          
           } 
        
    
  


resize method may cause unexpected destruction and will cause crash in Label::updateBuffer.
_batchCommands.clear(); should be added before it so that old invalid objects will not be used.

Closing comment (2020-12-28T02:26:05Z): This issue has already been posted in #20000 and #20478 and may also related to #20622 and #20626, but it's still not fixed.
@minggo could you please look at it?